近期项目遇到了问题,有个asp.net web程序仅仅能在IE7 执行。如今xp都淘汰了,大家都用IE8-IE11,因此这个web app也须要升级 适应全部IE版本号。照成IE版本号不兼容的问题主要来致document.createElement方法的调用,如:

function addStyleNo(value, cannotDel) {

    if (!value) {

        value = '';

    }

    var tb = $('tbodyStyle');

    var tr = tb.insertRow();

    var td1 = tr.insertCell();

    td1.style.width = '20px';

    td1.style.height = '20px';

    if (!cannotDel) {

        var imgDel = document.createElement("<img alt = '' src='./images/delete.gif' onclick = 'delScTr(this)' style='cursor:pointer' />");

        td1.appendChild(imgDel);

    }



    var td2 = tr.insertCell();

    td2.style.height = '20px';

    var txt = document.createElement("<input type = 'text' class = 'ip-bx-ro' value = '" + value + "' />");

     td2.appendChild(txt);



}

这个系统的js太多太多,大家对这个系统的业务也不熟悉。我先前是把这个document.createElement 用jquery来取代。

var imgDel = jq("<img alt = '' src='./images/delete.gif' onclick = 'delScTr(this)' style='cursor:pointer' />")[0];

var txt = jq("<input type = 'text' class = 'ip-bx-ro' value = '" + value + "' />")[0];

后来发现要改的地方太多了。于是想想有没有简单的方法, 最后把矛头指向覆盖document.createElement 方法的实现。

document.createEl = document.createElement;

        document.createElement = function (obj) {

            if (obj.toString().indexOf("<") > -1) {

                return jq(obj)[0];

            }

            else {

                return document.createEl(obj);

            }

        }

眼下在ie下还没有发现什么异常情况。

熟悉前端的都知道,火狐默认状态非window.open的页面window.close是无效的

网上有非常多人说,在火狐的地址栏输入:about:config然后找到dom.allow_scripts_to_close_windows;把false改为true

看着这些人的说法,不得不说我蛋疼了

我做的是站点。我怎么去改用户的浏览器设置。我不是搞病毒的啊

难道我在站点公布一个公告“如需用火狐訪问本站点,请改动浏览器器设置……”

那恐怕我会死得非常快

关闭是不可能的。那就搞点折中方案。。跳转到about:blank嘛

 <script type="text/javascript">
function CloseWebPage() {
if (navigator.userAgent.indexOf("MSIE") > 0) {
if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
window.opener = null; window.close();
}
else {
window.open('', '_top'); window.top.close();
}
}
else if (navigator.userAgent.indexOf("Firefox") > 0) {
window.location.href = 'about:blank ';
//window.history.go(-2);
}
else {
window.opener = null;
window.open('', '_self', '');
window.close();
}
}
</script>

JavaScript 覆盖document.createElement 方法 解决window.close在火狐下不兼容问题)的更多相关文章

  1. JavaScript 覆盖document.createElement 方法

    最近项目遇到了问题,有个asp.net web程序只能在IE7 运行,现在xp都淘汰了,大家都用IE8-IE11,因此这个web app也需要升级 适应所有IE版本.照成IE版本不兼容的问题主要来致d ...

  2. 网页关闭(解决window.close在火狐下不兼容问题)

    熟悉前端的都知道,火狐默认状态非window.open的页面window.close是无效的 网上有很多人说,在火狐的地址栏输入:about:config然后找到dom.allow_scripts_t ...

  3. console.log的一个应用 -----用new方法生成一个img对象和document.createElement方法创建一个img对象的区别

    我用两种方法来生成img对象,第一种方法是用new方法,第二种方法是用document.createElement方法. var img1 = new Image(); var img2 = docu ...

  4. javaScript 对象的hasOwnProperty方法打印window自定义属性

    for (var name in window) { if (window.hasOwnProperty(name)) { window.console.log ( name + " : & ...

  5. document.createElement方法的使用

    我们在使用createElemen方法t创建一个元素节点的时候,似乎在IE下面怎么写都可以,但切换到FF等其它浏览器却总是会报错. 比如我们要创建一个input元素,那么在IE下,我们可以有多种写法: ...

  6. document.createElement()方法

    document.createElement()是在对象中创建一个对象,主要和appendChild() 方法或者insertBefore() 方法联合使用. appendChild() 方法在节点的 ...

  7. window.frames[]在Firefox下无法兼容的解决方式

    html代码段: <iframe id="fr" src="ProjectTree.aspx?IsFree=true&f=yes&IsCheckPr ...

  8. 解决jquery操作checkbox火狐下第二次无法勾选问题

    最近在学习jQuery(版本jquery-1.9.1.js),要求用jQuery实现全选/全不选.反选,在IE(IE8)中没有问题,但在火狐浏览器中调试的时候出现了一些小问题,达不到效果. html代 ...

  9. 解决Clover在win 10下的兼容问题

    周五闲的蛋疼,把系统升级到win10.周一早上过来,发现Clover 无法使用了,各种崩溃,查阅了官网,发现Clover确实只兼容到win8.网络上给出解决方案的确是用qttabbar,qttabba ...

随机推荐

  1. aJax学习之Ajax工作原理

    转自:http://www.cnblogs.com/mingmingruyuedlut/archive/2011/10/18/2216553.html 在写这篇文章之前,曾经写过一篇关于AJAX技术的 ...

  2. Linux编程环境介绍(3) -- linux下的c/c++程序开发

    目录: 1. 编辑器( Vi ) [vi 与 vim] vi(visual interface)是linux系统最重要的文本编辑器, 所有的 Unix-Like 系统都会内置vi文本编辑器.  vim ...

  3. 定义一个runtime的Annotation

    import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(value ...

  4. codevs 1256 打鼹鼠 LIS

    题目链接 题目描述 Description 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢把头探出到地面上来透透气的. 根据这个特点阿Q编写了一个打鼹鼠的游戏:在一个n*n的网格中,在某些时 ...

  5. js跨域及解决方法

    什么是跨域 JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象.但在安全限制的同时也给注入iframe或是ajax应用上带来了不少麻烦.这里把涉及到跨域的一些问题简单地整理一下: 首 ...

  6. 在Windows环境下部署Axis2/C服务

    Apache Axis2/C是C语言实现的网络服务引擎,基于Axis2架构,支持SOAP1.1和SOAP1.2协议,并且支持RESTful风格的Web service. 下面是本人在Windows 7 ...

  7. data pump(数据泵)

    先给出oracle给出的一个定义: “Oracle Data Pump technology enables very high-speed movement of data and metadata ...

  8. 破解win7开机密码,又不取消密码

    Win7开机密码破解方法 1. 进入pe.(可用系统盘,或者u盘启动) 2.进入c:\windows\system32下 更改magnify.exe和cmd.exe的所有者为administrator ...

  9. S3C6410 GPIO操作接口

    在后面的驱动学习中,需要对GPIO进行一系列的操作,了解这些引脚操作有助于编码的效率. 一.配置GPIO S3C6410要使用其引脚时,需要对其进行配置,如配置为输入/输出/中断等功能,根据芯片手册来 ...

  10. nyoj三个水杯(bfs)

    三个水杯 时间限制:1000 ms  |           内存限制:65535 KB 难度:4   描述 给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个为空杯子.三个水杯之间相互 ...