Firefox javascript 书签在后台打开选项卡

发布于 2024-07-26 05:07:43 字数 1106 浏览 2 评论 0原文

我编写了一个书签来在中文词典中查找单词:

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 技术交流群。

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

发布评论

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

评论(4

橪书 2024-08-02 05:07:44

在 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

少女情怀诗 2024-08-02 05:07:44

不,不是通过 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.

漫漫岁月 2024-08-02 05:07:44

显然,这仅适用于以前打开的窗口,而不适用于根窗口。

使用相同的方式调用 window.open
窗口名称为已存在的
window,将 URL 加载到该窗口中
并给出窗口的引用
后退。 窗口没有获得焦点,
它的 opener 属性没有改变,并且
window.open 的第三个参数是
被忽略。 可以使用焦点方法
手动给予窗口焦点。

var oldWin = window.open("url.html","oldName"); 
oldWin.focus(); // give focus 

Apparently this is only possible with previously opened windows, not the root window.

Calls to window.open with the same
window name as an already existing
window, loads the URL into that window
and gives a reference to the window
back. The window isn't given focus,
its opener property isn't changed, and
a third argument to window.open is
ignored. You can use the focus method
to give the window focus manually.

var oldWin = window.open("url.html","oldName"); 
oldWin.focus(); // give focus 
墨落画卷 2024-08-02 05:07:44

面对同样的问题,我只注意到如果你在打开窗口后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.

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