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 4 of 4
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts

    calling a function in an iframe

    i want to call a function that is located within the javascript of an iframe. Can that be done like this?


    document.getElementById('iframeOut').calc();

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if (frames['iframeOut'].calc) frames['iframeOut'].calc();

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    ty very much, can u explain it for me tho. I know how to put it in my code and stuff i just want to learn more about javascript, and the only way to do that is ask questions

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    IFRAMES are schizo - half-element, half-window... so you need to keep in mind what you want to do with them before scripting. Get their window object to do 'window-like' things (call JS, change location) and their HTMLElement object to do 'element-like' things (CSS, e.g.). I'm still never sure what'll work. See if this confuses you:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">

    var HTML = '<script>function foo(){document.body.innerHTML+="foo<br />";}</'+'script>';

    </script>
    </head>
    <body>
    <iframe name="iframeOut" id="iframeOut" src="javascript&#58;parent.HTML"></iframe><br /><br />
    <a href="javascript&#58;;" onclick="if (frames['iframeOut'].foo) frames['iframeOut'].foo()">call foo()</a><br /><br />
    <a href="javascript&#58;;" onclick="alert(document.getElementById('iframeOut'))">
    alert(document.getElementById('iframeOut')---<b>what does this method return?</b></a><br />
    <a href="javascript&#58;;" onclick="alert(frames['iframeOut'])">
    alert(frames['iframeOut'])---<b>what does this reference (window.frames[] array) return?</b></a><br />
    <a href="javascript&#58;;" onclick="alert(document.getElementById('iframeOut') == frames['iframeOut'])">
    alert(document.getElementById('iframeOut') == frames['iframeOut'])---<b>Are they the same object?</b></a><br /><br />
    <a href="javascript&#58;;" onclick="alert(document.getElementById('iframeOut').tagName);
    alert(frames['iframeOut'].tagName)">
    alert(document.getElementById('iframeOut').tagName;
    alert(frames['iframeOut'].tagName---<b>Which one is an element object?</b></a>
    </body>
    </html>

    The src="javascript&#58;..." bit is just to avoid a second .htm file.


  •  

    Posting Permissions

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