【发布时间】:2011-03-05 05:29:33
【问题描述】:
我为 firefox 和 google chrome、safari 和 ie8+ 开发了一个扩展程序。它在 google 邮件界面中插入一个按钮。该按钮应该在电子邮件页脚中插入一些自定义文本。如果我访问标准谷歌邮件地址(您可以观看here 和here),这四个都可以正常工作。
相反,如果我通过 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