如何从 XUL 浏览器打开新窗口?

发布于 2024-10-04 08:47:43 字数 202 浏览 0 评论 0原文

我想知道,是否可以处理 Xul 浏览器组件打开新窗口的请求?我尝试更改 window.open 函数,但看起来它从未被调用。 在新窗口中打开的所有链接都不会在我的应用程序中打开。

我在主题,但提供的解决方案没有表现出不同的行为。

有什么提示吗?

(顺便说一句,我正在开发一个独立的应用程序,而不是 Firefox 的扩展)

I'm wondering, is it even possible to treat the request for the Xul Browser component to open a new window? I tried changing the window.open function, but looks like it's never called.
All links that open in a new window are not opening in my application.

I found this page on the subject, but the provided solution is showing no different behavior.

Any hint on this?

(by the way, I'm developing a stand alone application, not a Firefox's extension)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时间你老了 2024-10-11 08:47:43

我假设您在 XULRunner 应用程序中,并且您正在尝试从浏览器中的非 chrome 源(例如 HTTP 或本地文件)加载 chrome URL。虽然启用 UniversalXPConnect 和 UniversalBrowserWrite 可能会有所帮助,但它们也存在安全风险(因为网络上的任何任意脚本都可以使用它们),因此它们往往在浏览器中被禁用(例如,在 Firebug 中运行该行会给您一个例外):

>>> netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
Error: A script from "http://stackoverflow.com" was denied UniversalXPConnect UniversalBrowserWrite privileges.

您尝试使用代码库安全主体并看看这是否会产生影响怎么样? (http://www.mozilla.org/projects/security/components/signed-scripts.html#codebase)。对于我来说,Firebug 确实允许我在使用一个又大又难看的对话框确定后获得额外的权限,但仍然不允许我使用 window.open 打开 Chrome URL。下一步可能是尝试更改您的conf文件以使用contentaccessible,以便可以访问内容的相关部分(请参阅https://developer.mozilla.org/en/Chrome_Registration#contentaccessible)。

为了避免在提升权限时出现讨厌的消息,您可以尝试自动为正确的文件设置权限,如 http://forums.mozillazine.org/viewtopic.php?f=38&t=1769555

另外,请确保检查浏览器类型(https://developer.mozilla.org/en/XUL/Attribute/browser.type)。如果浏览器类型不是 chrome,那么可能值得尝试将其设为 chrome,看看是否会产生影响。

如果我的任何假设是错误的,请回复我,我会尝试其他方法。

I'm assuming you are in a XULRunner application, and that you are trying to load a chrome URL from a non-chrome source in a browser (e.g. HTTP or local file). While enabling UniversalXPConnect and UniversalBrowserWrite can be helpful, they are also a security risk (since any arbitrary script on the web could use them), so they tend to be disabled in browsers (for example, running that line in Firebug will give you an exception):

>>> netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
Error: A script from "http://stackoverflow.com" was denied UniversalXPConnect UniversalBrowserWrite privileges.

How about you try using codebase security principals and see if that makes a difference? (http://www.mozilla.org/projects/security/components/signed-scripts.html#codebase). For me in Firebug it does allow me to get the additional permissions after I OK it with a big, nasty looking dialog), but still doesn't allow me to open a Chrome URL with window.open. The next step is probably to try changing your conf file to use contentaccessible so that the relevant parts of your content are accessible (see https://developer.mozilla.org/en/Chrome_Registration#contentaccessible).

To avoid the nasty message when elevating permissions, you could try setting permissions for the right files automatically as described at http://forums.mozillazine.org/viewtopic.php?f=38&t=1769555.

Also, make sure you check the browser type (https://developer.mozilla.org/en/XUL/Attribute/browser.type). If the browser type is not chrome, then it might be worth trying making it chrome and seeing if that makes a difference.

If any of my assumptions are wrong get back to me and I will try something else.

辞慾 2024-10-11 08:47:43

普通js不行吗?

window.open(url,windowname,flags);

does normal js not work?

window.open(url,windowname,flags);
醉态萌生 2024-10-11 08:47:43

据我所知有两种方法。

第一个是将 browser.chromeURL 首选项设置为包含 的 chrome URL。内容窗口尝试打开的页面将加载到给定的浏览器中。

第二种方法是使用您定义的对象来设置属性 window.browserDOMWindow 来实现 nsIBrowserDOMWindow 接口。如果您使用选项卡式界面,这允许您将打开的呼叫转移到选项卡中。注意:选项卡式浏览首选项必须设置为允许窗口转移到选项卡中,否则 XULrunner 将依赖 browser.chromeURL

There are two ways that I know of.

The first is to set the browser.chromeURL preference to a chrome URL that contains a <browser type="content-primary">. The page that the content window tried to open will load into the given browser.

The second is to set the property window.browserDOMWindow with an object that you define to implement the nsIBrowserDOMWindow interface. This allows you to divert the open call into a tab, if you are using a tabbed interface. Note: the tabbed browsing preferences must be set to allow windows to be diverted into tabs, otherwise XULrunner will fall back on browser.chromeURL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文