如何从Firefox插件编辑`窗口`属性? [英] How to edit a property on `window` from Firefox addon?

查看:170
本文介绍了如何从Firefox插件编辑`窗口`属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个插件来修改窗口中的一个值。



让我们举个例子简单的窗口:

 < 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.originalTarget 指的是该页面的文档元素。要访问页面的窗口元素,可以使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆