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
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Retrieving the srcElement from an iFrame

    When attaching a onkeydown event to an iFrame, is there some way to determine what element raised the event?

    I can do this in a non iFramed page by using event.srcElement.type, but when using an iFrame, it comes back as 'undefined'.

    Also event.srcElement.tagName, when using an iFrame, returns as 'body' instead of 'input'.

    OR ... should I be able to attach the onkeydown in each page that is displayed in the iFrame?

    Like I said above, it does work when not in an iFrame, but when I use the iFrame, the code no longer works on each page.

    Thanks,
    Carl J

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    ok here is what i think you are looking for:

    main document source code:
    Code:
    <html>
    <head>
    <script type=text/javascript>
    function getElm(e){
    var ELM=I1.event.srcElement;
    if(ELM.type){
    alert(ELM.tagName+", "+ELM.type);
    }}
    </script>
    </head>
    <body>
    <iframe src=poker.html height=500 width=600 name='I1'></iframe>
    </body>
    </html>
    source code for iframe document:
    Code:
    <html>
    <head><title>your iframe</title></head>
    <body onclick="parent.getElm(event);">
    
    <input type=button value=click><input type=text value='blahblahblah'><br>
    <table><tr><td height=100 width=100 bgcolor=red>click</td></tr></table>
    
    </body>
    </html>
    Last edited by brandonH; 12-19-2007 at 03:33 AM.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

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