新标签打开时防止文档失去焦点 [英] Prevent document losing a focus when new tab is opened
问题描述
$(e).append(
$(< ; a>)。attr('href',url)
.attr('target','_blank')
.text(text)
);
如何防止文档在新标签打开时失去焦点? b
我想要在后台打开新选项卡,而不必将焦点切换到其中。
<$ p $在这个问题上被接受的答案: p>
$( '一个[目标= _空白]')removeAttr( '目标')。
使用相同问题的最上面的答案,试试这个:&b
$ b
< a href =your_urlonclick =window.open('#','_ blank'); window.open(this.href,'_ self' );>
使用问题被接受的答案,试试这个: Fiddle。 这里第十个参数设置 Let's have a simple code like this: How can I prevent document losing a focus when new tab is opened? I want a new tab to be opened in background without switching a focus into it. Try using this javascript by using this question's accepted answer: Using the same question's most upvoted answer, try this aswell: Using this question's accepted answer, try this: Here the tenth parameter sets the 这篇关于新标签打开时防止文档失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b
函数openNewBackgroundTab(){
var a = document.createElement(a);
a.href =http://www.google.com/;
var evt = document.createEvent(MouseEvents);
// initMouseEvent的第十个参数设置ctrl键
evt.initMouseEvent(click,true,true,window,0,0,0,0,
true,false, false,false,0,null);
a.dispatchEvent(evt);
$ b ctrl
键是正确的。然后,就像 ctrl
+ 点击
,然后在另一个窗口中打开,而不会丢失焦点。$(e).append(
$("<a>").attr('href', url)
.attr('target', '_blank')
.text(text)
);
$('a[target="_blank"]').removeAttr('target');
<a href="your_url" onclick="window.open('#','_blank');window.open(this.href,'_self');">
function openNewBackgroundTab(){
var a = document.createElement("a");
a.href = "http://www.google.com/";
var evt = document.createEvent("MouseEvents");
//the tenth parameter of initMouseEvent sets ctrl key
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
true, false, false, false, 0, null);
a.dispatchEvent(evt);
}
ctrl
key to be true. Then that just acts like a ctrl
+ click
and then that's opened in an another window without losing focus.