Timmy
Timmy

Reputation: 12828

How to check location.href is completed?

I want open a window and then does something after it finishes loading, is there an easy way to do this?

my current code is something like:

cur_window = window.open( 'http://www.google.com' )
// does something when cur_window finishes loading

thanks

Upvotes: 0

Views: 2622

Answers (2)

zzzzBov
zzzzBov

Reputation: 179096

Assuming you're accessing pages within the Same Origin...

the "easy way" isn't as responsive as jQuery's ready event which can't be applied outside of the original window context:

cur_window.onload = function () {
  //new window has loaded
};

If you're trying to open http://www.google.com/ in a new window, you wont have any access to the window object, and therefor have no way of knowing when the new window has loaded.

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337600

The only way to do this is if you write code in the page which is opened in the popup to tell the parent page, the opener object in js, that it has finished loading.

In your example, as your are loading Google, this is not possible.

Upvotes: 1

Related Questions