Firefox XUL 从内容上下文调用函数

发布于 2025-01-07 13:43:36 字数 801 浏览 5 评论 0原文

我知道这个问题很早就被问过,但OP没有得到任何合适的答案。 所以问题是:

如何访问页面上下文以调用 FF 覆盖中的某些 js 函数(在我的例子中为工具栏)。

我有 元素和 onclick="nextTrack()"nextTrack 在包含的 JS 文件中声明。当我按下工具栏按钮时函数会执行,但我无法执行我确信页面上存在的函数。

我无法修改该页面,因为它是外部站点,但我真的想制作我的扩展。

当然,我可以(而且我确实)使用像 mainDocument.getElementById("player_play").click() 这样的东西,但是页面已经有一个具有所有功能的 audioPlayer 对象我需要:播放暂停下一个上一个等。

为了更加简洁,我做了一个扩展来控制vkontakte 的音频播放器社交网络(前苏联国家众所周知的社交网络)。因此,您可以在此处查看示例页面,也许它会有所帮助:http://vk.com/wall6843477_2327。 当您开始收听带有控件的栏时,必须出现您可以找到很多东西,例如audioPlayer.nextTrack(); audioPlayer.prevTrack(); 等

I know that this question was asked earlier but the OP didn't get any suitable answer.
So the question is:

How to access page context to call some js function in FF overlay (toolbar in my case).

I have <toolbarbutton> element with onclick="nextTrack()". nextTrack declared in the included JS file. Function executes when I press toolbar button, but I cannot exec function that I'm sure exists on the page.

I cannot modify the page, because it is an external site, but I really want to make my extension.

Of course I can (and I am) use something like mainDocument.getElementById("player_play").click(), but page already has an audioPlayer object that has all ability I need: play, pause, next, prev etc.

For more cleanliness I make an extension to control an audio player for vkontakte social network (well known social network in exUSSR countries). So you can look at example page here, maybe it can be helpfull: http://vk.com/wall6843477_2327.
When you start listening the bar with controls must appear you can find lot of stuff like audioPlayer.nextTrack(); audioPlayer.prevTrack(); etc.

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

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

发布评论

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

评论(1

梦忆晨望 2025-01-14 13:43:36

您不是直接访问内容,而是通过 XPCNativeWrapper。这意味着内容页定义的所有 JavaScript 属性都是不可见的(这是一项安全功能)。对于您的情况,最简单的安全解决方案是使用 javascript: 协议:

mainDocument.defaultView.location.href = "javascript:void audioPlayer.play()";

这样您将无法返回结果,但似乎您不需要这样做。

You aren't accessing content directly, you are rather going through XPCNativeWrapper. This means that all JavaScript properties defined by the content page are invisible (which is a security feature). In your case, the simplest secure solution is to use the javascript: protocol:

mainDocument.defaultView.location.href = "javascript:void audioPlayer.play()";

This way you won't be able to get a result back but from it seems that you don't need to.

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