opening new windows after specifc interval of time

2019-02-21 03:44发布

I am looking for javascript code which will open new tabs(windows) automatically after specific interval of time.

i have few websites over here, in this code which open automatically when i press the button on the html page.

I want these websites to open after specific interval. like, 1st website will open when user will press button "Open Windows", 2 nd website after 1 minute and 3 rd websites after 2 minutes.

eg.

<html>
<head>
<script type="text/javascript">
function open_win() {
window.open("http://www.google.com")
window.open("http://www.yahoo.com")
window.open("http://www.bing.com")
}
</script>
</head>

<body>
<form>
<input type=button value="Open Windows" onclick="open_win()">
</form>
</body>

</html>

Thank you,

sangram

2条回答
放荡不羁爱自由
2楼-- · 2019-02-21 04:10

In most modern browsers you are not allowed to call window.open programatically, like through a setTimeout.

The browser will simply ignore the window.open statement if it is not inside a callstack that is initiated by a direct user interaction, for instance a mouse click event.

The reason for this is that it is very annoying behavior - you probably won't find a single person who enjoys using a site that opens windows by itself.

So: reconsider what you are trying to do, there is bound to be a better way - one where you can work with the browser/user and not against it/him/her :)

查看更多
劳资没心,怎么记你
3楼-- · 2019-02-21 04:23
function open_win() {
    window.open("x.com");
    setTimeout("window.open('y.com')",60000);
    setTimeout("window.open('z.com')",120000);
}

This should open x.com then after one minute y.com and after two it should open z.com.

查看更多
登录 后发表回答