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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    iframe accessing variables

    Hey

    is it possible to access javascript variables in an iframe src page from the parent page, or vice versa. How do you do this? What about the DOM?

    thanks

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Code:
    <head>
     <title>
      Pi Calculator
     </title>
     <script language="JavaScript">
      function  getVarFromIframe(){alert(window.frames['ifrm'].a)}
    
     </script>
    </head>
    <body>
    <input type="button" onclick="getVarFromIframe()" />
     
    <iframe name="ifrm" src="test.htm" />
    </body>
    test.htm....

    Code:
    <html>
    <head>
    <script>
    var a = "hi from iframe";
    </script>
    </head
    <body>
    Hiya
    </body>
    </html>
    Last edited by DaveyErwin; 08-29-2011 at 06:54 PM.


  •  

    Posting Permissions

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