焦点选项卡或窗口 [英] Focus tab or window
问题描述
对于一个小应用程序,我从我的脚本中打开了几个窗口/选项卡.浏览器是打开窗口还是标签页当然不在我手里.
for a little app, I'm opening a few windows/tabs from my script. Whether the browser opens a window or a tab is of course not in my hand.
但是,我持有对新创建的 window
对象的引用,并且我确实从另一个窗口远程"更改了它们的内容.这一切都发生在同一个 document.domain
下,所以没有 xss 问题.
However, I hold the references to the newly created window
objects and I do change their content "remotely" from another window. This all happens under the same document.domain
so no xss problem.
问题是,我无法可靠地focus
那些创建的窗口/标签.由于我正在为客户编写一个非常具体的应用程序,因此我只将 Firefox 定位为浏览器.我的一个选择当然是做一个 remoteWindow.alert('foobar');
把那个窗口/标签放在前面,但这很丑,不是吗.
The problem is, I cannot reliably focus
those created windows/tabs. Since I'm writing a very specific app for a customer, I'm only targeting Firefox as browser. One option I have is of course just to do a remoteWindow.alert('foobar');
to get bring that window/tab up front, but that is pretty ugly isn't it.
我找到了这个答案 如何像 alert() 一样聚焦窗口/选项卡?
那里说,Firefox 有一个允许脚本焦点的选项.所以最后我的问题是,那个选项是什么?我在 about:config
中搜索了标签"和焦点",但没有找到任何相关内容.
and it's said there, that Firefox has an option to allow script focus. So finally my question is, what is that option ?
I searched the about:config
for "tabs" and "focus" but didn't find anything related.
如何配置?
推荐答案
我看到的唯一解决方案是在新窗口中强制弹出,因为似乎没有办法聚焦另一个选项卡.此解决方案还要求您更改 Tools > 中的默认 Javascript 安全设置.选项 >内容选项卡
并单击Enable Javascript
复选框旁边的Advanced
按钮并选中中间框以允许聚焦窗口.
The only solution I see, is to force the popup in a new window, since there doesn't seem to be a way to focus another tab. This solution also requires you to change the default Javascript security settings in Tools > Options > Content tab
and click on the Advanced
button next to Enable Javascript
checkbox and check the middle box to allow focusing windows.
要强制使用窗口而不是选项卡,请使用 win = window.open("http://www.google.com", "test" ,"modal=yes");
然后随时调用 win.focus();
.
To force the use of a window rather than a tab, use win = window.open("http://www.google.com", "test" ,"modal=yes");
and then call win.focus();
whenever you feel like it.
实际上忘了提及这只是 FF 的事实.
Actually forgot to mention the fact that this is FF only.
这篇关于焦点选项卡或窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!