I am trying to create a function to open an URL automatically after some seconds.
What i have tried until now (that is now working in my android browser and chrome) is the code below:
$(document).ready(function() {
setTimeout(function() {
'window.open("http://google.com")', 2000);
});
});
Any idea?
Your
setTimeoutcall isn’t quite right – you’re actually just declaring a string and a number, then doing nothing with them. Change it as follows:Secondly, see the docs for window.open: It accepts a second parameter, which determines the name of the window to open. If you set this to
_blank, you’re telling the browser to open a new window (or tab) rather than replace the current page.However, you might run into trouble with the browser’s popup blocker. Generally, opening a new window or tab should be initiated after a
clickevent.