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

发布于 2024-10-19 22:03:18 字数 3086 浏览 2 评论 0原文

我为 firefoxgoogle chromesafariie8+ 开发了扩展程序。它将一个按钮插入谷歌邮件界面。该按钮应该将一些自定义文本插入电子邮件页脚。如果我访问标准谷歌邮件地址(您可以观看此处此处 )。

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

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

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

在 firebug 中:

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

I've developed an extension for firefox and google chrome, safari and ie8+. It inserts a button into the google mail interface . The button is supposed to insert some custom text into the email footer. It works fine on all of the four if i access the standard google mail address (you can watch it here and here).

Instead, if i access gmail through google apps, it almost all goes down the pipe. The only addon hat works well is the google chrome one. In all the others, the button is correctly added but when i click it this doesn't add anything into the email footer and produces the following errors.

In firefox i get the following jquery error console:

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

In firebug :

 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

Also, in Safari :

 ReferenceError: Can't find variable: toggleEncryptFooter

In internet explorer only composing the mail works, forwarding and replying doesn't.

Here's my jquery code that is injected into the gmail webpage :

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

燕归巢 2024-10-26 22:03:18

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

看来,从 Google Apps 的“实验室”选项卡中禁用 Google 日历小工具似乎可以完成这项工作。现在一切正常。希望这会帮助别人。

I solved the problem . Somehow!

It seemed that disabling the Google Calendar gadget from the labs tab in Google Apps seemed to do the job. Now everything works fine. Hope this will help someone else.

梦巷 2024-10-26 22:03:18

我必须替换

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 可能不是我正在查找的子 iframe为此,我必须使用额外的过滤:在本例中,是我正在搜索的子 iframe 的类名称。

假设是伪装的魔鬼。

I had to replace

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

with

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

It seems that in the normal Google mail interface there is only one sub-iframe inside the iframe I'm working in, so gmailInst = jQuery("iframe", doc) does its job as long as this condition maintains.

If i activate a few labs gadgets that are implemented with iframes, then gmailInst = jQuery("iframe", doc) passes the first sub-iframe in the list which is probably not the one i'm looking for so i have to use extra filtering: in this case, the class name of the sub-iframe i'm searching.

Assumptions are devils in disguise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文