Click Event in IE&FoireFox
Fx can't support "window.event" object. The follow codes will not act in Fx:
<input type="button" name="Button1" value="Button" onclick="javascript:doClick()">
<script language="javascript">
function doClick()
{
alert(window.event.clientX);
}
</script>
<script language="javascript">
function doClick()
{
alert(window.event.clientX);
}
</script>
The event in Fx should be send as a parameter of event function. The codes run in both IE and Fx:
<input type="button" name="Button1" value="Button" onclick="javascript:doClick(event)">
<script language="javascript">
function doClick(evt)
{
alert(evt.clientX);
}
</script>
<script language="javascript">
function doClick(evt)
{
alert(evt.clientX);
}
</script>
Notice that: event object in IE has event.x and event.y properties, but to Fx, they are event.pageX and event.pageY. You can use:
mX = event.x ? event.x : event.pageX;
The coordinate to parent object is clientX and clientY. These attributes can use both in IE and Fx.
We offen use [Object].[event]=[function] to define a event function, but in Fx it's a little diffent. So we must detect the explorer type first and then write different codes for it:
var agt=navigator.userAgent.toLowerCase();
var is_IE=(agt.indexOf("msie")!=-1 && document.all);
if(is_IE){
document.body.onload=InitPage;
}
else{
document.body.onload=InitPage();
}
var is_IE=(agt.indexOf("msie")!=-1 && document.all);
if(is_IE){
document.body.onload=InitPage;
}
else{
document.body.onload=InitPage();
}

浙公网安备 33010602011771号