最近項目遇到了問題,有個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下還沒有發現什麼異常情況。
熟悉前端的都知道,Firefox預設狀態非window.open的頁面window.close是無效的
網上有很多人說,在Firefox的地址欄輸入:about:config然後找到dom.allow_scripts_to_close_windows;把false改為true
看著這些人的說法,不得不說我蛋疼了
我做的是網站,我怎麼去改使用者的瀏覽器設定,我不是搞病毒的啊
難道我在網站發布一個公告“如需用Firefox訪問本網站,請修改瀏覽器器設定……”
那恐怕我會死得很快
關閉是不可能的,那就搞點折中方案。。跳轉到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>