View Full Version : Retrieving the srcElement from an iFrame

12-17-2007, 10:34 PM
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.

Carl J

12-19-2007, 04:13 AM
ok here is what i think you are looking for:

main document source code:

<script type=text/javascript>
function getElm(e){
var ELM=I1.event.srcElement;
alert(ELM.tagName+", "+ELM.type);
<iframe src=poker.html height=500 width=600 name='I1'></iframe>

source code for iframe document:

<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>