Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

srcElement in Firefox and Flock browsers

Status
Not open for further replies.

BigMentor

Technical User
May 15, 2009
10
GB
Hi
Help please

window.event.srcElement.id

Works in IE8

but not in Firefox and Flock browsers

need to make the WebPage "Cross-Browser" friendly.

What statement shoul I use please

tia
BigMentor
 
Hi feherke

Thank you for your reply.

I tried to include it in a short Test Page.

Works in IE8
BUT
not in Firefox or Flock

What stupid thing have I done wrong


<html>
<body>
<script language="JavaScript">
function function1()
{
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;

alert(targ.id);
}
</script>
<body id="myBody" onclick="function1();">
<button id="myButton1" onclick="function1();">Button One</button>
<button id="myButton2" onclick="function1();">Button Two</button>
</body>
</body>
</html>
 
Hi
Tried "function function1(e)" as suggested

No change in the results


<html>
<body>
<script language="JavaScript">
function function1(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;

alert(targ.id);
}
</script>
<body id="myBody" onclick="function1();">
<button id="myButton1" onclick="function1();">Button One</button>
<button id="myButton2" onclick="function1();">Button Two</button>
</body>
</body>
</html>
 
Hi

That way you are explicitly specifying the function calls as with no parameters. So the event objects will not be passed.
Code:
[b]<html>[/b]
[b]<body>[/b]
[b]<script[/b] [maroon]language[/maroon][teal]=[/teal][green][i]"JavaScript"[/i][/green][b]>[/b]
    function function1(e) {    
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;

        alert(targ.id);
    }
[highlight]document.body.onclick=function1[/highlight]
[highlight]document.getElementById('myButton1').onclick=function1[/highlight]
[highlight]document.getElementById('myButton2').onclick=function1[/highlight]
[b]</script>[/b]
[b]<body[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"myBody"[/i][/green][b]>[/b]
[b]<button[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"myButton1"[/i][/green][b]>[/b]Button One[b]</button>[/b]
[b]<button[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"myButton2"[/i][/green][b]>[/b]Button Two[b]</button>[/b]
[b]</body>[/b]
[b]</html>[/b]
Next time please post your code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] TGML tags.

Feherke.
 
Thank u - it works


Sorry about missing the Tags
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top