internet explorer - JavaScript works in IE, but not Firefox - Stack Overflow

admin2025-04-20  0

Same old same old, my javascript runs fine in IE but not with Firefox. I've followed all the forms, checked all the forums and responses, and what I've got coded up should work but it's not. Firebug shows the value as "undefined."

Here's what I've got; it's scaled down from a much bigger application, but it shows the same problem:

<html>
<head>
<script type="text/javascript">
function show_alert(evt)
{
if( !evt )
    evt = window.event;

var eSrc;
if( evt.srcElement )
    eSrc = evt.srcElement;
else
    eSrc = evt.target;

if( eSrc.tableisloaded == "showAlert" ) 
    alert("alert box: " + eSrc.name + "|" + eSrc.type);
}

</script>
</head>
<body>

<input type="button" name="clickme" tableisloaded="showAlert"
 onclick="show_alert(event);" value="Show alert box" />

 </body>
</html>

When I run this in IE, I get the alert, which means it is finding the "tableisloaded" argument. Firebug doesn't show it all.

So what am I doing wrong, and is there a way to access the argument? Will I need to change it to a parameter (onclick="show_alert(event,"showAlert");)? I am hoping NOT as it will require a major rewrite of a LOT of code.

Thanks

Same old same old, my javascript runs fine in IE but not with Firefox. I've followed all the forms, checked all the forums and responses, and what I've got coded up should work but it's not. Firebug shows the value as "undefined."

Here's what I've got; it's scaled down from a much bigger application, but it shows the same problem:

<html>
<head>
<script type="text/javascript">
function show_alert(evt)
{
if( !evt )
    evt = window.event;

var eSrc;
if( evt.srcElement )
    eSrc = evt.srcElement;
else
    eSrc = evt.target;

if( eSrc.tableisloaded == "showAlert" ) 
    alert("alert box: " + eSrc.name + "|" + eSrc.type);
}

</script>
</head>
<body>

<input type="button" name="clickme" tableisloaded="showAlert"
 onclick="show_alert(event);" value="Show alert box" />

 </body>
</html>

When I run this in IE, I get the alert, which means it is finding the "tableisloaded" argument. Firebug doesn't show it all.

So what am I doing wrong, and is there a way to access the argument? Will I need to change it to a parameter (onclick="show_alert(event,"showAlert");)? I am hoping NOT as it will require a major rewrite of a LOT of code.

Thanks

Share Improve this question asked May 28, 2010 at 14:34 kbersonkberson 4381 gold badge3 silver badges9 bronze badges 4
  • 4 "works in IE, but not Firefox" - Something is horribly wrong. – Eric Commented May 28, 2010 at 14:37
  • Its not that unmon, imho. Getting one to work fine is easy, getting code that works fine in both is the tricky part. – Nate Commented May 28, 2010 at 14:39
  • getting things to work in most other browsers is easy, getting it to work for EACH version of IE is a PITA – Justin Commented May 28, 2010 at 15:07
  • jQuery is like a super-strength headache tablet that makes this pain go away. – James Westgate Commented May 28, 2010 at 15:12
Add a ment  | 

2 Answers 2

Reset to default 11

Try eSrc.getAttribute("tableisloaded")

Also, if you want to be hip and trendy, you might consider making your pages HTML5 and calling your extra attribute "data-tableIsloaded". That way it'll validate.

<!doctype html>
<html lang="en">
<head>
<meta charset= "utf-8">    
<title>Added attributes</title>
<script type="text/javascript">

function show_alert(evt){
    evt= window.event || evt;
    var eSrc= evt.srcElement || evt.target; 
    if(eSrc.getAttribute('data-tableisloaded')== "showAlert"){
        alert("alert box: " + eSrc.name + "|" + eSrc.type);
    }
}
onload=function(){
    document.getElementsByName('clickme')[0].onclick=show_alert;
}

</script>
</head>
<body>

<input type="button" name="clickme" data-tableisloaded="showAlert" 
value="Show alert box" >

</body>
</html>

// pointy answered while I was still typing, and I gave him an upvote- but this is what he said....

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745148517a287491.html

最新回复(0)