admin管理员组文章数量:1404346
I need to make a little JS app to scroll automatically through a list of URLs. I've chosen to have the functionality in a pop-up, for various reasons.
The syntax to change the opening window's URL is:
window.opener.location.href = "";
This works fine with one URL, but if two statements are called, only one is executed. I experimented with an alert statement between two of the above statements, and the alert event made the second statement function properly:
window.opener.location.href = "";
alert("hello world");
window.opener.location.href = "";
Question is: does anyone know how to get the first and second window.opener statements to work, without the intervening alert();? Also, how can I add a pause between the two statements, so that the second executes a couple of seconds after the first?
Thanks so much!
I need to make a little JS app to scroll automatically through a list of URLs. I've chosen to have the functionality in a pop-up, for various reasons.
The syntax to change the opening window's URL is:
window.opener.location.href = "http://www.example.";
This works fine with one URL, but if two statements are called, only one is executed. I experimented with an alert statement between two of the above statements, and the alert event made the second statement function properly:
window.opener.location.href = "http://www.example1.";
alert("hello world");
window.opener.location.href = "http://www.example2.";
Question is: does anyone know how to get the first and second window.opener statements to work, without the intervening alert();? Also, how can I add a pause between the two statements, so that the second executes a couple of seconds after the first?
Thanks so much!
Share Improve this question edited Jun 8, 2010 at 0:43 Gordon Gustafson 41.3k25 gold badges119 silver badges159 bronze badges asked Jun 8, 2010 at 0:35 user360923user360923 111 gold badge1 silver badge2 bronze badges 2- see if that title works any better (if not change it back :). Hard to describe concisely. – Gordon Gustafson Commented Jun 8, 2010 at 0:44
- "This works fine with one URL, but if two statements are called, only one is executed" Which one? I suspect they're both executed, it's just that you only see the result from one of them. – T.J. Crowder Commented Jun 8, 2010 at 0:50
2 Answers
Reset to default 2You need to call setTimeout
, like this:
window.opener.location.href = "http://www.example1.";
setTimeout(function() {
window.opener.location.href = "http://www.example1.";
}, 5000); //5,000 milliseconds
Is the original location of the opener page also at http://www.example1.
? If not, then when the first statement executes and it changes the location of the opener to a different domain, then the window.opener
property bees not accessible -- hence the second statement fails.
版权声明:本文标题:JavaScript: 2 window.opener.location.href statements with alert() in between not functioning - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744790845a2625277.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论