与Jquery奇怪的firefox-safari-chrome-ie8 +扩展问题

时间:2011-02-28 21:32:05

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

我开发了 firefox 谷歌浏览器 safari ie8 + 的扩展程序。它在谷歌邮件界面中插入一个按钮。该按钮应该将一些自定义文本插入电子邮件页脚。如果我访问标准谷歌邮件地址(你可以观看herehere),它在所有这四个都可以正常工作。

相反,如果我通过谷歌应用程序访问gmail,它几乎都会进入管道。唯一的插件效果很好的是google chrome one。在所有其他按钮中,按钮被正确添加,但是当我单击它时,这不会在电子邮件页脚中添加任何内容并产生以下错误。

在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中,只编写邮件作品,转发和回复不会。

这是我的jquery代码,它被注入gmail网页:

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;
}

2 个答案:

答案 0 :(得分:1)

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

似乎从Google Apps的实验室标签中禁用 Google日历小工具似乎可以胜任。现在一切正常。希望这会帮助别人。

答案 1 :(得分:1)

我不得不替换

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的类名。

假设是伪装的恶魔。