让窗口保持焦点一键点击两页重定向 [英] Have Window Keep Focus After One Click Fires Two Page Redirects
问题描述
首先,祝大家节日快乐。
First of all, happy holidays to everyone.
我有一个锚元素可以触发两页重定向 - 一个通过 href
属性,一个通过 jQuery
。
I have an anchor element that fires two page redirects - one through the href
attribute, one through jQuery
.
<a id="myClick" target="_blank" href="http://www.google.ca">Google</a>
$('#myClick').on('click', function () {
window.location = 'http://www.stackoverflow.com';
});
这样可以正常工作,但新标签会获得焦点。我希望原始标签能够为用户保留焦点。我确实给了 window.focus()
a go但是,假设它不起作用。
This works fine, but the new tab gains focus. I'd like the original tab to keep the focus for the user. I did give window.focus()
a go but, as assumed, it didn't work.
I也尝试过使用这个答案的小提琴,但它只是解雇了新选项卡和原始页面(jsfiddle)保持相同的URL。 我编辑的小提琴来自链接的答案
I also did try working with the fiddle from this answer but it only fired the new tab and the original page (jsfiddle) remained the same URL. My edited Fiddle from linked answer
我怎么能让原始标签保持焦点?是不是我的手?
How could I go about having the original tab keep the focus? Is it out of my hands?
推荐答案
你无法使用javascript在后台打开标签,因为这是在用户设置的about:config中的首选项,您无法控制。设置为:
You can't open tabs in the background using javascript because this is set in the user's preferences in about:config, which you have no control over. The setting is:
browser.tabs.loadDivertedInBackground=true
这篇关于让窗口保持焦点一键点击两页重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!