近期项目遇到了问题,有个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. [C#参考]主线程和子线程之间的参数传递

    几个进程在大多数情况下要包含很多的子线程,那么他们之间免不了的要互相传递很多的参数,那么参数怎么传递的呢? 主线程向子线程传递参数的方法 第一种方法:Thraed类有一个带参数的委托类型的重载形式,这 ...

  2. Common Git command and mean (Windows)

    Config: git config --system git config --global git config --global merge.tool vimdiff Check config: ...

  3. zoj 3171 The Hidden 7's

    这道题,我在网上看到两种dp,不过基本原理是一样的,不过感觉还是后面的一种比较巧妙!因为我对动态不是很熟,自能加上一些自己的理解,写上注释. 1) #include <stdio.h> # ...

  4. SQL Server 通配符为目标字符的查找

    create table t(x int identity(1,1) primary key,v nvarchar(32));go insert into t(v) values('this is % ...

  5. GitHub Android 最火开源项目Top20 GitHub 上的开源项目不胜枚举,越来越多的开源项目正在迁移到GitHub平台上。基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要。利用这些项目,有时能够让你达到事半功倍的效果。

    1. ActionBarSherlock(推荐) ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库,通过一个API和主题,开发者就可以很方便 ...

  6. Android 流媒体系列(二)

    import java.io.IOException; import android.app.Activity; import android.content.ContentResolver; imp ...

  7. HDU 5758 Explorer Bo(树形DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5758 [题目大意] 给出一棵树,每条路长度为1,允许从一个节点传送到任意一个节点,现在要求在传送次 ...

  8. 字符串的MD5的32位加密和16位加密

    import java.security.MessageDigest; import java.util.Locale; public class MD5Util { public static St ...

  9. 使用vi编辑binary文件

    原理:使用xxd将当前文件转成hex格式,编辑,然后再转回去 /usr/bin/xxd xxd - make a hexdump or do the reverse 例子: 用binary模式启动vi ...

  10. jquery $.ajax $.get $.post的区别

    $.ajax 是 jQuery 底层 AJAX 实现,$.ajax是一种通用的底层封装,$.ajax()请求数据之后,则需要使用回调函数,有beforeSend.error.dataFilter.su ...