Web Analytics Made Easy -
StatCounter Targeting one iframe from within another - CodingForum

Announcement

Collapse
No announcement yet.

Targeting one iframe from within another

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Targeting one iframe from within another

    I would like to put two iframes on the same page. Then I want to be able to click on the links in one iframe and have them load pages into the other iframe. The first iframe will be a menu and the second will display the pages, just like with normal side-by-side frames. I want something unsual is why I'm trying this. Does anyone know what JavaScript I would have to put in the links of the first iframe? I bet this one will be a real head scratcher.
    Master Newbie http://dwightstegall.com/

  • #2
    Put this in the head of the link frame (be sure and give your target frame an ID):
    Code:
    <script type="text\javascript">
    
    function changePage(url)
    {
         document.getElementById('myFrameID').src=url;
    }
    </script>
    Assign your links like this:
    Code:
    <a href="#" onclick="changePage('http://www.codingforum.net');">Coding Forum</a>
    Basscyst
    Last edited by Basscyst; Feb 26, 2004, 06:09 PM.
    Helping to build a bigger box. - Adam Matthews

    Comment


    • #3
      HTML is enough.

      <a href="page.html" target="nameOfTargetIFrame">link</a>
      Glenn
      vBulletin Mods That Rock!

      Comment


      • #4
        Targeting one iframe from within another one

        Thanks Basscyst it worked after a couple of modifications. The reverse slash typo in the script tag and I had to add top.document to make it work like below.

        I hate nothing worse than asking for help. This the first time I have had to in 8 years. But I'm just starting to learn JavaScript.

        <script type="text/javascript">
        <!--
        function changePage(url)
        {
        top.document.getElementById('myFrameID').src=url;
        }
        //-->
        </script>

        <a href="javascript:void(0)" onclick="changePage('http://www.codingforum.net/');">CodingForum</a>

        Thanks for the speedy response.
        Master Newbie http://dwightstegall.com/

        Comment


        • #5
          HTML is enough.

          Thanks for trying to help Glen. But, your way only works if the links are on the same page as the iframe you are targeting. But, thanks anyway.
          Master Newbie http://dwightstegall.com/

          Comment


          • #6
            Here it is

            I have a test page setup so you can see what I was talking about. Sorry about the domain name but it's not mine. I just have an account there.

            http://www.tuff****.net/accounts/home/tips
            Master Newbie http://dwightstegall.com/

            Comment


            • #7
              Hmmmm wouldn't let me post the domain name

              Here it is.

              &#104;&#116;&#116;&#112;&#58;&#47;&#47;&#116;&#117;&#102;&#102;&#115;&#104;&#105;&#116;&#46;&#110;&# 101;&#116;&#47;&#97;&#99;&#99;&#111;&#117;&#110;&#116;&#115;&#47;&#104;&#111;&#109;&#101;&#47;&#116; &#105;&#112;&#115;&#47;
              Master Newbie http://dwightstegall.com/

              Comment


              • #8
                Re: HTML is enough.

                Originally posted by oldcrazylegs
                Thanks for trying to help Glen. But, your way only works if the links are on the same page as the iframe you are targeting. But, thanks anyway.
                It will work if you put name="main" in the target iframe.

                <A class="menu" onclick="changePage('main.htm');" href="main.htm" target="main">Main Introduction</A>

                <iframe src="main.htm" id="main" name="main">
                Glenn
                vBulletin Mods That Rock!

                Comment

                Working...
                X