解决JS在firefox和IE下差异问题(1)(2)
8.window.event问题
说明:window.event只能在IE下运行,而不能在Firefox下运行,这是因为Firefox的event只能在事件发生的现场使用.
解决方法:
IE:
- <inputnameinputname="Button8_1"type="button"
- value="IE"onclick="javascript:gotoSubmit8_1()"/>
- ...
- <scriptlanguagescriptlanguage="javascript">
- functiongotoSubmit8_1(){
- ...
- alert(window.event);//usewindow.event
- ...
- }
- </script>
- IE&Firefox:
- <inputnameinputname="Button8_2"type="button"
- value="IE"onclick="javascript:gotoSubmit8_2(event)"/>
- ...
- <scriptlanguagescriptlanguage="javascript">
- functiongotoSubmit8_2(evt){
- ...
- evtevt=evt?evt:(window.event?window.event:null);
- alert(evt);//useevt
- ...
- }
- </script>
9.event.x与event.y问题
说明:IE下,even对象有x,y属性,但是没有pageX,pageY属性;Firefox下,even对象有pageX,pageY属性,但是没有x,y属性.
解决方法:使用mX(mX=event.x?event.x:event.pageX;)来代替IE下的event.x或者Firefox下的event.pageX.
10.event.srcElement问题
说明:IE下,even对象有srcElement属性,但是没有target属性;Firefox下,even对象有target属性,但是没有srcElement属性.
解决方法:使用obj(obj=event.srcElement?event.srcElement:event.target;)来代替IE下的event.srcElement或者Firefox下的event.target.
11.window.location.href问题
说明:IE或者Firefox2.0.x下,可以使用window.location或window.location.href;Firefox1.5.x下,只能使用window.location.
解决方法:使用window.location来代替window.location.href.
12.模态和非模态窗口问题
说明:IE下,可以通过showModalDialog和showModelessDialog打开模态和非模态窗口;Firefox下则不能.
解决方法:直接使用window.open(pageURL,name,parameters)方式打开新窗口。如果需要将子窗口中的参数传递回父窗口,可以在子窗口中使用window.opener来访问父窗口.例如:varparWin=window.opener;parWin.document.getElementById(Aqing).value=Aqing;
- 上一篇:解析J2ME对话框选择功能的实现
- 下一篇:解析JS中实现打印的两大方式






