JavaScript: 2 window.opener.location.href statements with alert() in between not functioning - Stack Overflow

I need to make a little JS app to scroll automatically through a list of URLs.I've chosen to hav

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
Add a ment  | 

2 Answers 2

Reset to default 2

You 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744790845a4593904.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信