【发布时间】:2014-06-05 23:24:57
【问题描述】:
我正在尝试禁用 Firefox 扩展程序中的 beforeUnload 对话框,该扩展程序通过将窗口包装在 XPCNativeWrapper 中并使用 addeventlistener 重新定义 window.onbeforeunload 直到 FF28。
示例 JavaScript:
var win = new XPCNativeWrapper(window, "onbeforeunload", "event", "addEventListener()");
var beforeUnload = win.onbeforeunload;
win.onbeforeunload = null;
var newBeforeUnload = function(e) {
beforeUnload();
//code to remove dialog
}
win.addEventListener('beforeunload', newBeforeUnload, false);
当 beforeUnload 方法更改页面的位置时,这在 FF29 中停止工作。在 FF29 中,我收到错误“拒绝从脚本访问 'chrome://browser/content/page.html'”。
页面上的JS示例:
window.onbeforeunload = function() {
parent.frame2.location="page.html";
};
【问题讨论】:
-
您是否正在尝试编辑插件源代码?
标签: javascript firefox-addon onbeforeunload