wtm wtm - 1 year ago 148
Javascript Question

Javascript close an tab you just opened

I want to open a URL in a new window, and after x seconds or when the page is done loading I want to close it again.

I am now using:

window.open('http://otherurl.com', 'newwindow', 'width=300, height=250'); return false;

The 'otherurl' is not domain, so I cannot control that URL.

How can I do this?

Answer Source

window.open gives you a reference to that window, so:

var newWindow = window.open('http://otherurl.com', 'newwindow', 'width=300, height=250');

setTimeout(function() { newWindow.close(); }, 5000);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download