SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a link to an iframe problem

    Hi

    I assigned a function that can modify the src of the iframe to a link's onclick event. But when I cllcked the link, the whole page is directed to the url pointed to by href.

    function mainFrame(url) {
    .
    .
    document.getElementByID('..').src = url;
    }
    .
    .
    .
    <a href="/" onclick="javascript:mainFrame('url'); return true;"> link </a>


    What I want is after the link is clicked, content of the iframe should change according to the result of the function and everything should remain the same.
    Any advice is appreciated.

    Thanks

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Three different ways:

    HTML Code:
    <html>
    <head>
    <title>3 iframe Methods</title>
    </head>
    
    <body>
    <p>
    <a href="http://www.google.com/" 
    target="myframe">change link</a>
    <iframe width="100%" name="myframe" 
    src="http://www.yahoo.com/"></iframe>
    </p>
    
    <p>
    <a href="#" 
    onclick="document.getElementById('myframe2').src = 
    'http://www.google.com/'; return false;">change link</a>
    <iframe width="100%" id="myframe2" 
    src="http://www.yahoo.com/"></iframe>
    </p>
    
    <p>
    <a href="#" 
    onclick="parent.frames['myframe3'].location.href = 
    'http://www.google.com/'; return false;">change link</a>
    <iframe width="100%" name="myframe3" 
    src="http://www.yahoo.com/"></iframe>
    </p>
    </body>
    </html>
    The first one uses no javascript. The target of the iframe is all that's needed to change the location inside an iframe.

    -xDev

  3. #3
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. That helps a lot! Appreciated


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
  •