扩展程序如何访问其他页面中的全局变量 [英] How can extension access global variables in other pages
问题描述
< script language =javascript>
var g_GlobalVar1 =全局变量1;
< / script>
那么如何访问变量 g_GlobalVar1
通过Firefox扩展脚本的 DOMContentLoaded
处理函数? 为了安全起见,特权代码不直接访问网页,而是通过 .mozilla.org / en / XPCNativeWrapperrel =nofollow> XPCNativeWrapper 。这尤其意味着您通常无法读出网页添加的任何JavaScript属性。您可以绕过安全层并以 wnd的形式访问变量。 wrappedJSObject.g_GlobalVar1
但这不建议,你应该考虑使用一种替代方法(哪一个取决于你想要做的这个网页)。
There is a web page which contains the following parts:
<script language="javascript">
var g_GlobalVar1 = "Global Variable 1";
</script>
So how the variable g_GlobalVar1
can be accessed by the DOMContentLoaded
handler function of the Firefox extension script?
For security reasons, privileged code doesn't access web pages directly but through XPCNativeWrapper. This means in particular that you normally cannot read out any JavaScript properties that the web page added. You can bypass the security layer and access the variable as wnd.wrappedJSObject.g_GlobalVar1
but this isn't recommended and you should consider using an alternative approach (which one depends on what you are trying to do with this web page).
这篇关于扩展程序如何访问其他页面中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!