...

View Full Version : Retrieving the srcElement from an iFrame



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

Thanks,
Carl J

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

main document source 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:



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum