tags:

views:

62

answers:

3
document.getElementById(Iframe_id).contentWindow.addEventListener("blur", blurtest, true);

By using this line I have given the blur event to iframe. it is working.

But When in

function blurtest(e)
{
 alert(e.target.id); 
}

alert is used, but it gives value as Undefined.In other events it is working. So How to get the id of iframe in this blur function?.

A: 

Try the automatic variable this. It should contain the element on which the event was fired.

Aaron Digulla
A: 

When you load page into iFrmae, put into id of that iframe. So you can get the ID out of i by "this.getElementsByTagName('html')[0].id;"

bala3569
A: 

you have 2 ways, to use scope closures to remember the variable during set up:

var theID = Iframe_id;
document.getElementById(Iframe_id).contentWindow.addEventListener("blur", function( ){ blurtest( theID ), true);

or using a proper way to get the source element of an event

function blurtest( e )
{
    e = e || window.event;
    var obj = e.srcElement ? e.srcElement : e.target;
    alert( obj.getAttribute( 'id' ) );
}

good luck!

Dan Beam
Thanks a lot. it is really a good solution.
Pranjali
then give it an up click for me, :D
Dan Beam