Help targeting a link to iframe using javascript

Discussion in 'JavaScript' started by allofcraigs, Dec 27, 2009.

  1. #1
    Hi-

    I'm a javascript retard, and i don't know if what I'm about to say even makes sense.

    I need to target something like this:

    <a href="javascript:functionname('value')">the link</a>

    to an iframe:

    <iframe src="#" name="iframe"></iframe>

    ==========

    Any ideas? Thanks in advance
     
    allofcraigs, Dec 27, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    If I understood well what you wanted, so this is that you want

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
      <title>Iframe link</title>
    </head>
    
    <body>
    
    <p>
        <a href="#" onclick="javascript:document.getElementById('iframe').src = 'http://rubensargsyan.wordpress.com';">Link</a>
    </p>
    
    <iframe src="http://rubensargsyan.com" name="iframe" id="iframe" width="800" height="600"></iframe>
    
    </body>
    
    </html>
    
    Code (markup):
     
    s_ruben, Dec 27, 2009 IP
  3. allofcraigs

    allofcraigs Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi-

    No, it needs to be formatted like this:

    <a href="javascript:setContext('context')">link text</a>

    needs to target the iframe by name, not src - as follows:

    <iframe name="iframe"></iframe>

    I tried this:

    <a target="iframe" href="javascript:setContext('context')">link text</a>

    Of course, it didn't work, unfortunately.
     
    allofcraigs, Dec 27, 2009 IP