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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    linking to an iframe in another page

    i have been looking all over the web and i can't get to where i need to be to finish my page. basically i have two pages and if someone clicks a specific link from the first page i want it go to the other page but load a specific page in the iframe on the second page.

    i know how to use javascript to make a specific page load into an iframe but not how to make the page load into the iframe on another page. all i need to know is how to do it for one page then i think i can build the decision structure around it to make it work for more than one link (hopefully).

    any help will be greatly appreciated. thanks.

  • #2
    New Coder
    Join Date
    May 2005
    Location
    Los Angeles
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <html>
    <head>
    <title>iFrames</title>
    </head>
    <body bgcolor="#cccccc">
    <p>
    <a href="page1.html" target="contentFrame">page 1</a> |
    <a href="page2.html" target="contentFrame">page 2</a> |
    <a href="page3.html" target="contentFrame">page 3</a> |
    <a href="page4.html" target="contentFrame">page 4</a>
    </p>
    <iframe name="contentFrame" src="page1.html" width="500px" height="300px" scrolling="auto" frameborder="0"> Warning: Your browser does not support iframes.</iframe>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks but that wasnt it.

    i already knew how to do that. what i need to know is how to click a link on the first page that would then open up a new link and open up the appropriate page in the iframe according to what value was passed to the new page.

    i figure it requires passing a value but i have no idea how to do this in javascript.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I don't know exactly what you intend to do, but you might give your iframe and id as well, say id="contentFrame". Now you may reach the iframe loaded page's document as:

    document.getElementById('contentFrame').contentWindow.document
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ill rephrase my prob since i guess i didnt do a good job of explaining things before.

    let's say i have two pages, page A is just a regular web page. page B though is a regular web page with an iframe in it.

    what i want to happen is when a link on Page A is clicked, page B will load but it will also load up a specific page in the iframe, the page to load in the frame will be determined by the value passed to it from the link on page A.

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You may pass a parameter via address bar, same as a querry
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    please if you can dumb down how exactly to handle this. i have messed with javascript a very minimal amount.

  • #8
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi newfoundnoise82,

    i think I know what your problem is because i'm having the same myself. I found a solution but it is in PHP. So maby somebody can translate it to JavaScript?

    Here is it:

    ==========================================================

    Have the index page pass a simple variable in the query string, then have the page with `nav & iframe` use that variable to determine what to put in the iframe's contents by default.

    Using PHP as an example:
    If your navigation contents are "Work - About Us - Something else", the links could be "nav.php?action=work", "nav.php?action=about_us", "nav.php?action=something"

    I would then put the following block of code at the very top of the page

    PHP Code:
    switch($_GET['action']) {
    case 'work': $src='work.html'; break;
    case 'about_us': $src='about.html'; break;
    case 'something': $src='else.html'; break;
    default: $src='default.html'; break;
    }



    And when you declare your iframe, do it as follows:
    <iframe src ="<?=$src;?>"></iframe>

    ==========================================================

    Let's hope someone can help us!!

  • #9
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please try the following

    Your links in page A would be

    PHP Code:
    <a href="pageb.htm?iframepage1.htm">Iframe page 1</a><br>
    <
    a href="pageb.htm?iframepage2.htm">Iframe page 2</a><br
    In page B

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Document Title</TITLE>
    <
    script type="text/javascript">
    <!--

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

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

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


    </HEAD>
    <BODY>


    <iframe name="myiframe" id="myiframe" src=""></iframe>

    </BODY>
    </HTML> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #10
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yessssssss!!

    tnx Mr. J

    it works great!!! And just when I was giving up the hope!!
    so thanks again!!

  • #11
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    humzzzzzzz.....
    only now the url in the location-bar stays the same as the first press't button.
    check the site: http://home.planet.nl/~lind2304/deschans/

    And i'm working on a script that will also change the button when it's on the page. It's not working correctly with the 'loadIframe' function.

  • #12
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Just slightly puzzled here,

    You have implimented the script and the links in the first page but in all your other pages you have only put in the script and not changed the links therefore in these pages the script is non functional.

    Also the links in your other pages all use the target attribute to load the iframe?
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #13
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well i'm not sure what you mean. I did it exactly the way you told me to. It did look like a very simple sollution to me then. But with the things you're saying now, you make it seem harder then i thought it was.

    What can I do to solve the problem? Maby some script for the location-bar? And a (when opening iframe1, open image1) javascript for the navigation.

    (Sorry i don't know much about JavaScript)

  • #14
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    It's probably me getting confused.

    The location bar will only show the url of the parent page as far as I know
    Last edited by Mr J; 06-07-2006 at 02:10 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #15
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well it's not a big problem. But it's still something that should de fixed. I'm gonna look for something that will get the button to change to te right image.
    Thanks for your help anyway!! The most urgent thing is fixed, so that's a start!!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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