9

If I open a window (with window.open), can I detect when its URL changes (to a specific one), given that:

  • The initial URL for the window is on another domain (Facebook, to be precise)
  • The URL I'm interested in detecting is too

I need this for authentication. See "Desktop apps" at the bottom of this page.

Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
  • Is this running in a desktop app embedded browser? This is important as in regular web browsers you're not allowed to read back from the window object (returned by `window.open`) if it's on a different domain, but in a dektop web client control the rules may be more lax. – Jim Blackler May 02 '11 at 21:31
  • Are you embedding the browser into your desktop app? – Femi May 02 '11 at 21:32
  • It's in a browser, but I find the desktop app more convenient than redirecting to an actual URL in my site (because there are some checks which makes testing with a local version annoying). Still, that's possible if this fails. – Bart van Heukelom May 02 '11 at 21:33

2 Answers2

4

As long as the new url resides on a domain not considered equal to your own by the Same Origin Policy, then this will impossible.

Sean Kinsey
  • 37,689
  • 7
  • 52
  • 71
0

Well, one way I've found is to simply keep polling the window's location.href (using setTimeout), but it's hardly elegant.

Update: It doesn't work. I can console.log(newWin.location) just fine, but when I try to access href or hash I get cross-domain security errors.

Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301