admin管理员组文章数量:1415460
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
2 Answers
Reset to default 11Try 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....
本文标签: internet explorerJavaScript works in IEbut not FirefoxStack Overflow
版权声明:本文标题:internet explorer - JavaScript works in IE, but not Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745148515a2644809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论