Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loading a certain page in an iframe by identifying the bookmark via javascript

    Hi, i've a site and i would like to load a particular page in an iframe when a certain bookmark is in the location bar. What i came up with is the below code, but obviously it doesn't work.

    <script language="javascript">
    var isrc1 = window.location.href.indexOf("test");
    if ( isrc1 > 0)
    {
    alert(window.location.href)
    frames['myframe'].location.href = "test.htm"
    }
    </script>

    What i'm trying to do is, when the url is "http://www.mysite.com/index.htm#test", load test.htm in an iframe called myframe in index.htm.

    Hope someone can help me

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Using location.hash will return just the anchor name including the #.

    if (location.hash=="#test")
    {
    window.frames['myframe'].location.href = "test.htm";
    }

    You can put that in a function and call it onload so that you're sure that the iframe has loaded before you call it.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, using your code, i added this in

    <script language="javascript">
    function loader()
    {
    if (location.hash=="#test")
    {
    window.frames['myframe'].location.href = "test.htm";
    }
    }
    </script>

    and also added this to the iframe:

    <iframe name="myframe" onload=loader()>

    however when i load index.htm#test, the iframe will continually load a page w/o stopping. am i doing anything wrong? thanks

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You have an endless loop. And besides iframe onload is supported in IE only.
    What I meant in my previous post was onload of the main document not of the iframe.

    <body onload="loader()">
    <iframe name="myframe" src="about:blank"></iframe>
    </body>

    You may want to load a default page for the iframe so that javascript-disabled browsers can see something in the iframe.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i figured it out just before u posted... lol...

    thanks anyway for yr help

    i do have a default page loaded, i didn't add it in the code i posted


  •  

    Posting Permissions

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