Results 1 to 4 of 4

Thread: Help with iFrames and Javascript

  1. #1
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with iFrames and Javascript

    I know it can be done, because I've seen it before and was hoping one of you could help. I have on page with an iframe that I want to load different documents in. I want to be able to click on a link from another page that will tell the iframe what to load. This will be passed through the clicked linke (i.e. http://www.domain.com/index.htm?iframeurl=one.htm). I know how to do it with php, but i don't want to go that route just yet. Can anyone help me come up with the javacript code needed to pull this off? Thanks in advance!

    Jbjohn942

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Yeah. Easy.

    Code:
    <iframe src="whatever.html" id="html" name="html" width="200" height="200">Whoops!! Your internet browser doesn't support iFrames.</iframe> <input type="button" value="Clik" onclick="html.location.href='yada.html';">
    You guys are just plain fun.

    -magicyte

    P.S. (WOO HOO! THIS IS MY HUNDREDTH POST! AFTER I PRESS THE POST QUICK REPLY BUTTON, I WILL BE A REGULAR CODER! WHOOPEEE!!!)

  3. #3
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Please excuse me, but magicyte, your code does'nt work on FF.
    This line throws an error:
    Code:
    <input type="button" value="Clik" onclick="html.location.href='yada.html';">
    Maybe you mean something like this instead:
    Code:
    <input type="button" value="Clik" onclick="document.getElementById('html').src='yada.html';">
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here's the correct code working in all browsers:
    Code:
    <iframe src="whatever.html" id="html" name="html" width="200" height="200"></iframe>
    <noframes>
    <h2>Sorry, your browser doesn't support frames. Please enable frames or use a different browser to continue.</h2>
    </noframes>
    <input type="button" value="Click" onClick="document.getElementById('html').src='yada.html';">
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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