如何从Firefox插件编辑`窗口`属性? [英] How to edit a property on `window` from Firefox addon?
问题描述
我想做一个插件来修改窗口中的一个值。
让我们举个例子简单的窗口:
< html>
< head>
< title>< / title>
< script>
window.hello = 1;
< / script>
< / head>
< body>
< / body>
< / html>
使用
gBrowser.addEventListener(DOMContentLoaded,
function(e)
{
e.originalTarget.defaultView.hello = 2;
},false);
不会修改的值window.hello
。含义 e.originalTarget.defaultView!= window
。
如何访问纯窗口
?
e.target.defaultView
。但是,为了保持Mozilla安全协议的界限,您必须通过 wrappedJSObject
属性来访问窗口对象。总的来说,你可以改变这个变量: e.target.defaultView.wrappedJSObject.hello = 2
I want to make an addon that modifies one value on the window
.
Let's take for example a simple window:
<html>
<head>
<title></title>
<script>
window.hello = 1;
</script>
</head>
<body>
</body>
</html>
Using
gBrowser.addEventListener("DOMContentLoaded",
function (e)
{
e.originalTarget.defaultView.hello = 2;
}, false);
does not modify the value of window.hello
. Meaning e.originalTarget.defaultView != window
.
How can I access the pure window
?
e.originalTarget
refers to the document element of that page. To access the window element of the page, you use e.target.defaultView
. However, in order to stay withing the bounds of Mozilla's security protocols, you must access the window object through its wrappedJSObject
property. Overall, you'd change the variable like:
e.target.defaultView.wrappedJSObject.hello = 2
这篇关于如何从Firefox插件编辑`窗口`属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!