我为firefox和google chrome、safari和ie8+开发了一个扩展。它在 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;
}