JavaScript 覆盖document.createElement 方法 解决window.close在火狐下不兼容问题)
近期项目遇到了问题,有个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在火狐下不兼容问题)的更多相关文章
- JavaScript 覆盖document.createElement 方法
最近项目遇到了问题,有个asp.net web程序只能在IE7 运行,现在xp都淘汰了,大家都用IE8-IE11,因此这个web app也需要升级 适应所有IE版本.照成IE版本不兼容的问题主要来致d ...
- 网页关闭(解决window.close在火狐下不兼容问题)
熟悉前端的都知道,火狐默认状态非window.open的页面window.close是无效的 网上有很多人说,在火狐的地址栏输入:about:config然后找到dom.allow_scripts_t ...
- console.log的一个应用 -----用new方法生成一个img对象和document.createElement方法创建一个img对象的区别
我用两种方法来生成img对象,第一种方法是用new方法,第二种方法是用document.createElement方法. var img1 = new Image(); var img2 = docu ...
- javaScript 对象的hasOwnProperty方法打印window自定义属性
for (var name in window) { if (window.hasOwnProperty(name)) { window.console.log ( name + " : & ...
- document.createElement方法的使用
我们在使用createElemen方法t创建一个元素节点的时候,似乎在IE下面怎么写都可以,但切换到FF等其它浏览器却总是会报错. 比如我们要创建一个input元素,那么在IE下,我们可以有多种写法: ...
- document.createElement()方法
document.createElement()是在对象中创建一个对象,主要和appendChild() 方法或者insertBefore() 方法联合使用. appendChild() 方法在节点的 ...
- window.frames[]在Firefox下无法兼容的解决方式
html代码段: <iframe id="fr" src="ProjectTree.aspx?IsFree=true&f=yes&IsCheckPr ...
- 解决jquery操作checkbox火狐下第二次无法勾选问题
最近在学习jQuery(版本jquery-1.9.1.js),要求用jQuery实现全选/全不选.反选,在IE(IE8)中没有问题,但在火狐浏览器中调试的时候出现了一些小问题,达不到效果. html代 ...
- 解决Clover在win 10下的兼容问题
周五闲的蛋疼,把系统升级到win10.周一早上过来,发现Clover 无法使用了,各种崩溃,查阅了官网,发现Clover确实只兼容到win8.网络上给出解决方案的确是用qttabbar,qttabba ...
随机推荐
- Java文本编辑器中遇到的问题详解
今天介绍文件的读取和写入,分别用FileReader,FileWriter 1,FileWriter类(字符输出流类) 构造方法:FileWriter fw = new FileWriter(Stri ...
- [LeetCode]题解(python):142-Linked List Cycle II
题目来源: https://leetcode.com/problems/linked-list-cycle-ii/ 题意分析: 给定一个链表,如果链表有环,返回环的起始位置,否则返回NULL.要求常量 ...
- Module中引用Module中的Activity时报错了,错误是找不到R文件中的id引用
1.好像库modul和主modul不能有相同名字和layout文件 2.资源文件名冲突导致的
- nyist 202 红黑树(二叉树中序遍历)
旋转对中序遍历没有影响,直接中序输出即可. #include <iostream> #include <cstdio> using namespace std; int n; ...
- 不是技术牛人,如何拿到国内IT巨头的Offer(1)
转自:http://developer.51cto.com/art/201404/436685.htm 不久前,byvoid面阿里星计划的面试结果截图泄漏,引起无数IT屌丝的羡慕敬仰.看看这些牛人,N ...
- linux 之进程间通信-------------InterProcess Communication
进程间通信至少可以通过传送打开文件来实现,不同的进程通过一个或多个文件来传递信息,事实上,在很多应用系统里,都使用了这种方法.但一般说来,进程间 通信(IPC:InterProcess Communi ...
- linux核心之进程管理
进程就是处于执行期的程序(目标码存放在某中介质上).进程并不仅仅局限于一段可执行程序代码,通常还包括其他资源,例如打开的文件,挂起的信号,内核内部数据,处理器状态,一个或多个具有内存映射的内存地址空间 ...
- CSS小tip整理
CSS小tip整理 1.利用css在列表靠头和末尾添加箭头: /* 左箭头*/ ol a[rel="prev"]:before { content: "\00AB&quo ...
- Andy's First Dictionary
Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...
- BZOJ 1497: [NOI2006]最大获利( 最大流 )
下午到周六早上是期末考试...但是我还是坚守在机房....要挂的节奏啊.... 这道题就是网络流 , 建图后就最大流跑啊跑啊跑... --------------------------------- ...