Results 1 to 3 of 3

Thread: How to detect iframe src after serverside redirect?

  1. #1
    Join Date
    Jun 2006
    Location
    Birmingham
    Posts
    39
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy How to detect iframe src after serverside redirect?

    Hi everyone, I'm looking for a solution to this problem...

    re: http://art.bwdp.org.uk/

    If you click the RANDOM button, the iframe will load a fixed url which will then be redirected on the serverside to a random url. Then when you click Save, it detects the iframe's src from before it was redirected and displays the old src in an alert.

    Does anyone know... How can I detect the correct iframe src, using JavaScript?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    You have set the src attribute (when doing a random image) of the iframe to:

    Code:
    v1.php
    Now, at least as far as I can tell, there is something about that page that generates its own unique id for itself when it loads or something like that, but however it is done, it is done after you set the iframe's src attribute. So querying the iframe's src attribute will only give you:

    Code:
    v1.php
    However, since the iframe's location has changed, this will give you what you are after:

    Code:
    window.frames[0].location.href
    Example usage, replace:

    Code:
    onclick="alert(document.getElementById('DisplayFrame').src);"
    with:

    Code:
    onclick="alert(window.frames[0].location.href);"
    Notes: This will only work for pages on the same domain (not a problem with your demo pages, if the situation changes and you spread this out across more than one domain, there could be problems). The [0] refers to the first frame (in this case iframe) in the window. Iframe's locations must be queried of the iframe as a part of the window's frames collection, not as part of the document's elements collection.

    An alternative would be to generate the random query string id on the top page instead, then set the src attribute of the iframe, with the page v1.php not generating a unique id for itself. Then you could query the iframe's src attribute and get an accurate report.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Birmingham (07-17-2008)

  4. #3
    Join Date
    Jun 2006
    Location
    Birmingham
    Posts
    39
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks, jscheuer1. It works.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •