Firefox javascript 书签在后台打开选项卡
我编写了一个书签来在中文词典中查找单词:
javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('%E8%AF%8D%E8%AF%AD',''))};if(Qr)(function(){window.open('http://nciku.com/search/all/'+Qr);})();
这将打开一个新选项卡,其中包含您所选单词或在提示符下输入的单词的搜索结果。 有没有办法在后台加载新标签? 我想将焦点集中在我正在查看的页面上,然后再查看搜索结果。
Firefox 中有一个选项“当我在新选项卡中打开链接时,立即切换到它”,但这没有帮助。
编辑:请注意,这是供我使用的,因此告诉我如何更改 Firefox (3.0.11) 设置来执行此操作的答案也可以。 我还尝试了以下修改,但它仍然集中在新选项卡上。
javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('%E8%AF%8D%E8%AF%AD',''))};if(Qr)(function(){var%20oldWin=this;window.open('http://nciku.com/search/all/'+Qr);oldWin.focus()})();
编辑2:
环顾四周,看看我是否能找到答案,我看到这个人遇到了相反的问题(新选项卡没有获得焦点,但他希望他们拥有它),但没有解决方案:
Possible to set tab focus in IE7 from JavaScript
显然有关于 _tab 的讨论HTML 5 中的目标,但这对我没有多大帮助。
http://forums.whatwg.org/viewtopic.php?t=185&highlight=tab+focus
(显然,作为一名新用户,我只能发布一个链接,所以我已经破坏了它)
如果这是不可能的。
I've written a bookmarklet to look a word up in a Chinese dictionary:
javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('%E8%AF%8D%E8%AF%AD',''))};if(Qr)(function(){window.open('http://nciku.com/search/all/'+Qr);})();
This opens a new tab with search results for your selected word or a word you type in at the prompt. Is there a way to load the new tab in the background? I'd like to keep the focus on the page I'm looking at, and look at the search results later.
There is an option "When I open a link in a new tab, switch to it immediately" in Firefox, this doesn't help.
Edit: Note that this is for my use, so an answer that tells me how to change Firefox (3.0.11) settings to do this would work as well. Also I've tried the following modification, but it's still focusing the new tab.
javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('%E8%AF%8D%E8%AF%AD',''))};if(Qr)(function(){var%20oldWin=this;window.open('http://nciku.com/search/all/'+Qr);oldWin.focus()})();
Edit 2:
Looking around to see if I can find an answer I see this guy who's got the opposite problem (new tabs don't get focus, but he wants them to have it), but with no resolution:
Possible to set tab focus in IE7 from JavaScript
There's apparently talk about a _tab target in HTML 5, but that doesn't help me much.
http:/ /forums.whatwg.org/viewtopic.php?t=185&highlight=tab+focus
(apparently as a new user I can only post one link, so I've mauled it)
This seems pretty broken browser behaviour if this is impossible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 FireFox 中输入 about:config 并将 browser.tabs.loadDivertedInBackground 更改为 true。
这对我的浏览器书签很有用。
来源:http://lifehacker.com/263940/force-在后台打开的链接
In FireFox type about:config and change browser.tabs.loadDivertedInBackground to true.
This has worked for me with browser bookmarklets.
source: http://lifehacker.com/263940/force-links-to-open-in-the-background
不,不是通过 JavaScript 以编程方式。 您无法控制用户的浏览器首选项,只有他们可以控制。
此外,即使您确实可以控制它,您也不应该这样做,因为它破坏了浏览器为您提供的脚本的控制权。 如果用户希望在后台打开页面,他们应该能够控制它,而不是作为开发人员的您。
No, not programmatically through JavaScript. You don't have control over the user's browser preferences, only they have control over that.
Moreover, even if you did have control over that, you shouldn't do it, because it undermines the control that your script is given to you by the browser. If the user wants a page to open in the background, they should be able to control it, not you, as the developer.
显然,这仅适用于以前打开的窗口,而不适用于根窗口。
Apparently this is only possible with previously opened windows, not the root window.
面对同样的问题,我只注意到如果你在打开窗口后alert()执行某些操作,Firefox将不会切换到新打开的选项卡。
Facing the same issue, I only noticed that if you alert() something just after opening the window, Firefox would not switch to the newly opening tab.