【问题标题】:Weird firefox-safari-chrome-ie8+ extension issue with JqueryJquery 出现奇怪的 firefox-safari-chrome-ie8+ 扩展问题
【发布时间】:2011-03-05 05:29:33
【问题描述】:

我为 firefoxgoogle chromesafariie8+ 开发了一个扩展程序。它在 google 邮件界面中插入一个按钮。该按钮应该在电子邮件页脚中插入一些自定义文本。如果我访问标准谷歌邮件地址(您可以观看herehere),这四个都可以正常工作。

相反,如果我通过 google 应用程序 访问 gmail,它几乎都会失败。唯一运行良好的插件帽子是谷歌浏览器。在所有其他人中,该按钮已正确添加,但是当我单击它时,这不会在电子邮件页脚中添加任何内容并产生以下错误。

在 Firefox 中,我得到以下 jquery 错误控制台:

 Error: Permission denied to access property 'ownerDocument' Source File: chrome://sendsecurefree/content/jquery.js Line: 16

在萤火虫中:

 uncaught exception: [Exception... "Security Manager vetoed action"  nsresult: "0x80570027 (NS_ERROR_XPC_SECURITY_MANAGER_VETO)"  location: "JS frame :: chrome://sendsecurefree/content/jquery.js :: anonymous :: line 16"  data: no] Line 0

另外,在 Safari 中:

 ReferenceError: Can't find variable: toggleEncryptFooter

在Internet Explorer中只写邮件,转发和回复不行。

这是我注入到 gmail 网页的 jquery 代码:

function toggleEncryptFooter() {

var canvasBody = getGmailCanvasBody();

// get the button element
var documentul = getGmailCanvasDoc();
divul = jQuery(".dX.J-Jw", documentul);      
var encryptButton = divul.find("#encrypt");

//first, check if we already have an encrypt footer
var encryptFooter = jQuery("#encrypt_footer", canvasBody);
if(encryptFooter.length != 0) {
    //we have the footer inserted, delete it
    encryptFooter.remove();

    // style the button to no footer
    encryptButton.html('Enable Encryption');
    encryptButton.removeClass('downer');
    encryptButton.addClass('upper');
} else {
    //add the footer
    var doc = document;
    var head   = jQuery('head', doc);
    var textul = head.find("div#textul",head);

    // text was inserted in injectScript / gmailadder.js into head of canvas_frame
    getGmailCanvasBody().append('<div id="encrypt_footer">' + textul.html() + '</div>');     

    // style the button to footer added
    encryptButton.html('Disable Encryption');
    encryptButton.removeClass('upper');                      
    encryptButton.addClass('downer');
}
}

// gets the head element of the document
function getGmailHead(){
    var doc = document;
    var body = jQuery('head', doc);  
return body;
}

 // gets the body element of the document   
 function getGmailCanvasBody() {
var doc = document;

gmailInst = jQuery("iframe", doc);
    if(gmailInst.length==0) {
        //exit now, we are not on compose
        return null;
}
return gmailInst.contents().find('body');
 }

 // get the document object    
 function getGmailCanvasDoc() {
var doc = document;
var body = jQuery('body', doc);
var canvas_frame = jQuery('iframe#canvas_frame', body);
     if(canvas_frame.length==0) {
         //exit now, we are not on gmail
         return null;
          }

var canvas_doc = canvas_frame[0].contentDocument;

return canvas_doc;
}

【问题讨论】:

  • 我在这里猜测,但在我看来,这可能与 XSS/same-origin-policy 有关。 Google Apps 邮件 URL 可能与 Gmail URL 不同。
  • 不。如果我访问相同的链接 [link]mail.google.com/mail/?shva=1#compose :标准界面有效,通过谷歌应用程序访问的界面不适用于 firefox 和 safari。但是,谷歌浏览器扩展适用于所有这些
  • 希望我不会在这个令人沮丧的问题上浪费 1 周的时间!!!
  • 谢谢!我从来不知道它的存在;我不是一个粗鲁的男孩!我接受了一些答案。

标签: javascript jquery firefox-addon google-chrome-extension safari-extension


【解决方案1】:

我解决了这个问题。不知何故!

似乎从 Google Apps 的实验室标签中禁用 Google 日历小工具 似乎可以完成这项工作。现在一切正常。希望这对其他人有帮助。

【讨论】:

    【解决方案2】:

    我不得不更换

    gmailInst = jQuery("iframe", doc);
    if(gmailInst.length==0) {
        //exit now, we are not on compose
        return null;
    }
    

    gmailInst = jQuery("iframe.Am.Al", doc);
    if(gmailInst.length==0) {
        //exit now, we are not on compose
        return null;
    }
    

    似乎在正常的 Google 邮件界面中,我正在使用的 iframe 内只有一个子 iframe,所以 gmailInst = jQuery("iframe", doc) 的工作是只要这种状态保持。

    如果我激活了一些使用 iframe 实现的实验室小工具,那么 gmailInst = jQuery("iframe", doc) 会传递列表中的第一个子 iframe,这可能不是我的那个'正在寻找,所以我必须使用额外的过滤:在这种情况下,我正在搜索的子 iframe 的类名。

    假设是伪装的魔鬼。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多