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 to the CF scene
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting the parent for a document

    Dear Great Coders,

    I am having some trouble to get the id of the parent of a document which is iframe1 here. As you can see it the <javascript> is residing in the javascript section. Do mind giving me some ideas?

    Yes, I know. I can insert the javascript on the top, but believe me i cant for some purpose because I am intergrating many other codes into it.

    <html>
    <iframe id="iframe1">
    <html>
    <head>
    <javascript>
    </head>
    <body>
    </body>
    </html>
    </iframe>

    </html>
    Last edited by tweakmy; 06-18-2010 at 12:48 PM.

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,708
    Thanks
    0
    Thanked 237 Times in 232 Posts
    Hi there tweakmy,

    and a warm welcome to these forums.

    Try...
    Code:
    
    
    <script type="text/javascript">
    
    function init() {
    if(parent.document.getElementsByTagName('iframe')[0]!=undefined) {
       alert(parent.document.getElementsByTagName('iframe')[0].id);
      }
     }
    if(window.addEventListener){
       window.addEventListener('load',init,false);
     }
    else { 
    if(window.attachEvent){
       window.attachEvent('onload',init);
      }
     }
    </script>
    
    coothead


  •  

    Posting Permissions

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