开发者

close tab when a new site has loaded

开发者 https://www.devze.com 2023-04-04 03:36 出处:网络
I am wondering whether it\'s possible to close a tab as soon as a new site has loaded, without having to use js on the new site. I basically want to cl开发者_运维技巧ose the tab when we receive any co

I am wondering whether it's possible to close a tab as soon as a new site has loaded, without having to use js on the new site. I basically want to cl开发者_运维技巧ose the tab when we receive any content from the new site.

I use this to trigger a click event which submits a form:

$('#target_attack').click();

I tried putting window.close() right after this, but the tab closed without having loaded the new site.

I also tried to pause the script for 3 seconds and then close the tab, but for some reasons the site then won't load.

I also thought about using sessions but this means I would have to use js on the other site too, which I want to avoid.

I hope you guys can help a little javascript noob C: Thanks in advance!


Guessing you are using window.open to open it in a new tab.

var winPop = window.open(url);
$(winPop.document).ready(function() {
    window.close();
});


If javascript didn't open the window, javascript cannot close the window. Otherwise, window.close() is what you use.

You can try to bypass this security restriction (bad plan), but I do not believe this works on newer versions of any browser:

window.top.opener=null;
window.close();

See the docs - Firefox: https://developer.mozilla.org/En/DOM:window.close, IE: http://msdn.microsoft.com/en-us/library/ms536367%28VS.85%29.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消