简体   繁体   English

我无法在xul中为我的浏览器元素访问docShell?

[英]I am unable to access docShell for my browser element in xul?

<browser id="search" type="content-targetable" src="www.google.com">
</browser>

Javascript Code JavaScript代码

// I am using script to set the property of browser element

var x=document.getElementById('search');

x.docshell.allowAuth="false"     // The code stops here

x.docshell.allowPlugin="false"   //This does not work

As with many XUL tags, the <browser> tag isn't inherently "special" - the "special" functionality is added by XBL . 与许多XUL标记一样, <browser>标记并不是固有的“特殊”标记-XBL添加了“特殊”功能。 The important thing is that XBL bindings are added via CSS rules and for these CSS rules to apply the element has to be inserted into the document. 重要的是,通过CSS规则添加了XBL绑定,并且要使这些CSS规则生效,必须将元素插入文档中。 So it is important to insert the element first and only access the special properties after that. 因此,重要的是首先插入元素,然后再访问特殊属性。 Of course, in this case some asynchronous initialization might be required as well so you better do something like: 当然,在这种情况下,可能还需要进行一些异步初始化,因此您最好执行以下操作:

var browser = document.createElement(browser);
parent.appendChild(browser);
window.setTimeout(initBrowser, 0);

function initBrowser()
{
  x.docShell.allowAuth = false;
  ...
  browser.loadURI("...", null, null);
}

Note that it's docShell (your example used wrong captalization) and that allowAuth is a boolean, not a string. 请注意,它是docShell (您的示例使用了错误的大写形式),并且allowAuth是布尔值,而不是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM