我正在尝试在 Google Chrome版本62.0.3202.94 中在后台打开新窗口。我通过在记事本中键入并复制粘贴到 F12 开发者控制台来运行代码。
这是我迄今为止尝试过的代码,它改编自各种Google搜索结果:
var url = "https://stackoverflow.com/";
function test1(){
var w = window.open(url);
w.blur();
window.focus();
}
function test2(){
window.open(url);
window.open().close();
}
function test3(){
window.open(url, "s", "width= 640, height= 480, left=0, top=0, resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no").blur();
window.focus();
}
我输入了test1()
和test2()
以及test3()
,然后按Enter键而未达到我想要的效果:新页面刚刚打开并获得焦点。
我有机会这样做吗?
请注意对浏览器和版本的重视。
答案 0 :(得分:0)
这仅适用于在后台打开新窗口,不适用于新标签页
window.open('http://google.com','','height=500,width=500');
window.open().close();
不要为了邪恶而使用炮弹