tags:

views:

631

answers:

2

I'm using an iframe to integrate two of our customer's apps. I'd like the iframe's location to persist even when the top level window is refreshed.

Example:

  • user loads http://myserver/main.page?target="sub.page" in his browser
  • my javscript code sets the source of the iframe to "sub.page"
  • user clicks a link within the iframe and the iframe's source becomes "othersub.page"
  • user clicks a link within the top level window , outside of iframe, that links to http://myserver/main.page
  • javascript somehow automatically updates the iframe's source back to "othersub.page"

I can workout all the logic I need to take the iframe update actions and pass variables around. My issue is how to track the iframe's src value.

I need a way to detect that the iframe's src has changed. The only thing I can think of is "polling" the value. I'd be interested to find out if someone has a better idea.

Thanks

+1  A: 

You can also add a 'load' event handler to this frame. Every time this event occurs, you would store the framed documents' location in a cookie.

IIRC, when the content of an iframe changes, the SRC attribute doesn't change. IMO, you have to read the location of the document.

Rafael
Right. This makes sense. One of my sub apps is hosted on different server. Will cross-site-scripting restrictions prevent me from reading the iframe's document object? Thanks
Mr Grieves
A: 

The load event will tell you when a new page loaded in the iframe, but as you say, you wont have permission to read the src property.

If the content of the iframe could load another iframe, which loads a page from the same domain as the root page, then this inner page can call javascript on the root page (since they are on same domain), and pass on info like the src string you wanted. Example

Leon van der Walt