iframe access in Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kathy123
    New Member
    • Dec 2007
    • 1

    iframe access in Javascript

    Hi,

    I am a total newbie in Javascript programming. I am developing a web page which has an iframe (with external URL links). I have a link in the main page which when clicked should result in simultaneous clicks on the main link (opening a new window) and a click on the link in the iframe, which should open in the original window. How is it possible???? Please remember that I am a newbie. I request the help of my geek friends out here. Thanx in advance.

    Kathy
  • Cainnech
    New Member
    • Nov 2007
    • 132

    #2
    Hi Kathy,

    Let's see if I get it right. You've got a page with an iframe in it.

    When clicking a link on the parent window (so the big page where the iframe is put in) you would like to have two pages loaded? One in the parent window and one in the iframe ?

    If that's the case then this is the code:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function link(url1,url2) {
    
    window.open(url1,"content");
    window.open(url2,"newwindow","width=400,height=200,toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes")
    
    }
    //-->
    </script>
    </head>
    <body>
    
    <table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
    <td width="100%" height="100%" align="center" valign="top">
    <iframe src="http://www.sevensheaven.nl/images/producten/illustration-illustratie_smiley-emoticon_04.jpg" width="500px" height="500px" name="content" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
    </td>
    </tr>
    <tr>
    <td width="100%" height="100%" align="center" valign="top">
    <br />
    <input type="button" onClick="link('http://www.google.com','http://www.yahoo.com')" value="Click Here"></td>
    </tr>
    </table>
    </body>
    </html>
    Some explanations might be in order if you would like to change the script to your needs.

    In the javascript function you'll see two properties in that function (url1 & url2). These are put there to prevent you from having to place a new function for every link you want to place. So if you have 7 different buttons with links, you just have to repeat
    Code:
    <input type="button" onClick="link('http://www.google.com','http://www.yahoo.com')" value="Click Here">
    and change the names of the url's.

    In this example the first url loads into the iframe and the second one loads in a popupwindow.

    Note that there are a lot of properties in the second window.open
    These are not mandatory, but I included them just to let you see what you can do with your popupwindow. Only the first two statements are neccessary (that's the url and the destination window).

    Just two more things:

    "content" is the name of the iframe. If you change it, you should also change the name in the function above. And you can also use the <a href> tag to call on the javascript in the following way:

    Code:
    <a href="javascript:link('http://www.google.com','http://www.yahoo.com')">Click here</a>
    I hope this helps you.

    Greets,

    Cainnech
    Last edited by Cainnech; Dec 26 '07, 12:52 AM. Reason: forgot something

    Comment

    Working...