近期项目遇到了问题,有个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++学习之嵌套类和局部类

    C++学习之嵌套类和局部类 局部类 在一个函数体内定义的类称为局部类. 局部类中只能使用它的外围作用域中的对象和函数进行联系,因为外围作用域中的变量与该局部类的对象无关.在定义局部类时需要注意:局部类 ...

  2. 有一个警告:Could not open/create prefs root node

    WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. 虽然程序也能正常运 ...

  3. Python3 关于UnicodeDecodeError/UnicodeEncodeError: ‘gbk’ codec can’t decode/encode bytes类似的文本编码问题

    以下是小白的爬虫学习历程中遇到并解决的一些困难,希望写出来给后来人,如有疏漏恳请大牛指正,不胜感谢! 首先,我的代码是这样的 import requests url = 'http://www.acf ...

  4. java核心技术学习笔记之一程序设计概述

    Java 核心技术之一程序设计概述 一.   Java语言的特点 简单行 :取经于C++,排除了C++不常用的指针.结构等,增加垃圾回收. 面向对象:与C++不同是单继承,但是可以继承多接口.完全面向 ...

  5. java axis web service

    编写 java调用web service的客户端比较简单,其中webservice为上一篇gsoap创建的server. package clientTest; import java.rmi.Rem ...

  6. Linux的几个概念,常用命令学习

    Linux的几个概念,常用命令学习---------------------------------设备名装载点// 通过装载点访问设备-------------------------------- ...

  7. Codeforce 424C Magic Formulas 找规律

    题目链接:http://codeforces.com/contest/424/problem/C 题意:求Q值 思路:找规律 显然能够得到一个矩阵 把这个矩阵画出来就能发现一个横向的规律和一个主对角线 ...

  8. GDB调试之core文件(如何定位到Segment fault)

    core dump又叫核心转储,当程序运行过程中发生异常,程序异常退出时,由操作系统把程序当前的内存状况存储在一个core文件中,叫core dump.(内部实现是:linux系统中内存越界会收到SI ...

  9. js字面量

    以前一直对js字面量模棱两可. '字面量是一种表示值的记法.' js字面量(literal) 分为以下几个 number literal        8   就是数字字面量 string liter ...

  10. C#第三方zip解压压缩工具,带事例源码

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using ICSharpCode. ...