ie兼容火狐
来源:互联网 发布:虚拟专用网络端口号 编辑:程序博客网 时间:2024/04/19 23:07
1. 火狐中所有使用event相关的代码无法使用.
event是IE封装过的全局对象,控制所有事的事件,但是这个对象在火狐中不存在,所以在火狐中无法使用,特别是event.keyCode也是无法取得的。
解决方法:
下面这段JS重新封装了EVENT对象,直接在页面引用,原先的events代码均可试用于火狐:
<script>
/*firefox----这段js重新封装了event对象,经验证可以在火狐下支持!----*/
function __firefox(){
HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style);
window.constructor.prototype.__defineGetter__("event", __window_event);
Event.prototype.__defineGetter__("srcElement", __event_srcElement);
}
function __element_style(){
return this.style;
}
function __window_event(){
return __window_event_constructor();
}
function __event_srcElement(){
return this.target;
}
function __window_event_constructor(){
if(document.all){
return window.event;
}
var _caller = __window_event_constructor.caller;
while(_caller!=null){
var _argument = _caller.arguments[0];
if(_argument){
var _temp = _argument.constructor;
if(_temp.toString().indexOf("Event")!=-1){
return _argument;
}
}
_caller = _caller.caller;
}
return null;
}
if(window.addEventListener){
__firefox();
}
/*end firefox------------------------------------------------*/
</script>
2. event.returnValue = false无法使用
虽然重新封装了event但是这个方法还是无法支持
解决方法:
调用event.returnValue = false时候使用以下方法:
function setReturnValueFalse()
{
if(document.all)
{
window.event.returnValue = false;
}
else
{
event.preventDefault();
}
}
3. 某些click()事件无法触发
有些时候我们会通过js直接调用对象的click()事件,但是有的时候在火狐中却不起作用。
解决方法:
首先查看调用的控件有没有定义onclick事件,火狐中如果没有定义onclick事件的话,调用click()是什么都不会做的,比如:
<a href=”http://www.5173.com”>5173</a>
A标签在IE下面直接调用该控件click就会跳转到对应的页面,但是火狐下不会,必须添加一个跳转的方法:
<a href=”http://www.5173.com” onclick=”javascript:if(this.href.length!=0) window.open(this.href)”>5173</a>
如果在确定有onclick事件的时候仍然调用click()失效,请使用以下方法
function controlClick(obj)
{
if(document.all)
{
obj.click();
}
else
{
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, true);
obj.dispatchEvent(evt);
}
}
Obj为需要调用click()方法的对象。
4. 清空File控件的内容时候,方法失效。
如果使用document.execCommand(‘Delete’>这个方法清空File控件内容的话,在火狐下是没办法适用的。
解决方法:
调用以下方法
function emptyFile(cid)
{
var $=document.getElementById;
document.getElementById(cid).outerHTML?$(cid).outerHTML=$(cid).outerHTML:document.getElementById(cid).value="";
}
其中cid为控件id
5. 调用innerText无效
在火狐中是不支持innerText对象的,请使用innerHTML或者jquery的text()方法
6. 使用onkeypress事件时候参数使用event.keyCode无效
解决方法:
使用onkeydown方法代替onkeypress或者使用火狐下单独使用event.charCode
- ie兼容火狐
- 兼容IE 和火狐
- innerText 兼容火狐 ie浏览器
- innerText兼容火狐和IE
- innerText兼容火狐和IE
- 火狐、ie不兼容汇总
- 兼容IE火狐的回车
- IE和火狐兼容文章javascript兼容
- IE和火狐兼容的AJAX写法
- ie火狐兼容的几个js问题
- IE和火狐的不兼容
- ie和火狐都兼容的滚动
- JS 取消冒泡事件 兼容火狐IE
- ie与火狐兼容 部分整理
- CSS滤镜实现火狐、IE兼容
- 2010IE和火狐全面兼容写法
- 上下左右滚动图片(兼容ie和火狐)
- 火狐与IE浏览器兼容代码
- 如何在html页面中使用框架
- 26个Jquery使用小技巧(jQuery tips, tricks & solutions)
- pku2295 A DP Problem
- 网页游戏 1
- 随机数的生成问题??
- ie兼容火狐
- 利用CSS3的新功能实现(椭)圆角边框和图片边框 (圆角)
- 数据库的备份和还原代码
- 使用jxl,Servlet,JSP 动态生成excel文件并提示下载的简单方法
- 元素的尺寸和位置
- 测试数据生成工具TestDataBuilder、DBmonster、dataFactory试用中
- 历史轨迹回放
- do while
- 4.5--如何给一个对话框加入预览区域?