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 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question help with javascript please!

    Hi!
    I have a main page (main.php) and the are 2 iframes in it. The menu is located in main.php and what I want to happen is that the 2 iframes will change its contents when a link in the menu is clicked. Is there a way for me to do this?

    I tried this code

    Code:
    function loadIframe(iframeName, url) {
    
    frames[iframeName].location.href = url;
    
    }
    but I can't make it work when I place it in my link tag like this

    Code:
    <a href="#" onClick="javascript:loadIframe('mIframe','lesson.php')">google</a>
    WHat's wrong with what I'm doing? Please somebody help me 'xoz I'm stuck!

  • #2
    Regular Coder
    Join Date
    Nov 2004
    Location
    Edinburgh, SCO
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey,

    you don't need JS to do that.

    Code:
    <a href="lesson.php" target="mIframe">google</a>
    will do the job just fine.

    Frank

  • #3
    New Coder
    Join Date
    Sep 2004
    Location
    Brazil
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    heres one thing:

    instead of:
    <a href="#" onClick="javascript:loadIframe('mIframe','lesson.php')">google</a>
    put the onclick content on the href:
    <a href="javascript:loadIframe('mIframe','lesson.php')">google</a>
    if you want to use "onclick" to call a function just do this:
    <a href="#" onClick="loadIframe('mIframe','lesson.php');return false;">google</a>
    dont add the "javascript:" thing


    another thing, Im not sure but I though you could call an <iframe> by writing down this: "document.iframename.location.href" you dont need to have the "frames.iframe..." unless you confused <iframe>s with <frameset>s...

    hope that helped
    gabriel


  •  

    Posting Permissions

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