problem with looping iframe

Discussion in 'JavaScript' started by shredtone, Feb 24, 2010.

  1. #1
    Having some issues with some java where my page gets stuck in a loop.

    Briefly what I am doing is clicking a link on "Page A" that opens a document in a iframe on "Page B"

    my link on page A is like this:

    <a href="PageB.html?document.html" target="_self">

    On page B my body tag is this:

    <body onload="pictures1.location.href = self.location.search.substr(1)">

    and Iframe code this:

    <iframe name="pictures1" src="document.html" width="100%" height="600" frameborder="0" ></iframe>


    Now this works almost perfectly. The links from page A work fine but if you try to access page B directly, instead of the src="document.html" loading in the iframe the frame loads all of Page B inside the frame. This creates and endless loop of page B loading inside itself in the iframe.

    Is there anyway to prevent this and to load the proper source?
     
    shredtone, Feb 24, 2010 IP
  2. SeoKungFu

    SeoKungFu Active Member

    Messages:
    206
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    check on page B if top.location is itself into the js hook to prevent reloading if its the main one ?
     
    SeoKungFu, Feb 24, 2010 IP
  3. shredtone

    shredtone Peon

    Messages:
    105
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, I figured it out. For anyone else looking into how to do this.

    Page A link: <a href="PageB.html?document.html">

    Page B below Title tag:

    <script type="text/javascript">
    <!--

    function loadIframe(){
    if (location.search.length > 0){
    url = unescape(location.search.substring(1))

    window.frames["pictures1"].location=url
    }
    }

    onload=loadIframe
    //-->
    </script>

    and Page B iframe code: <iframe name="pictures1" id="pictures1" src="document.html" width="100%" height="750" frameborder="0" ></iframe>

    Thanks for your reply seoKungFu
     
    shredtone, Feb 25, 2010 IP