Js 根据不同浏览器弹出窗口

时间:2023-03-09 06:42:26
Js 根据不同浏览器弹出窗口
 /// <reference path="intellisense/jquery-1.2.6-vsdoc.js" />
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var ua_match = /(trident)(?:.*rv:([\w.]+))?/.exec(userAgent) || /(msie) ([\w.]+)/.exec(userAgent);
var is_ie = ua_match && (ua_match[1] == 'trident' || ua_match[1] == 'msie') ? true : false; function LoadDialogWindow(URL, parent, loc_x, loc_y, width, height) {
if (is_ie)//window.open(URL);
window.showModalDialog(URL, parent, "edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:" + width + "px;dialogHeight:" + height + "px;dialogTop:" + loc_y + "px;dialogLeft:" + loc_x + "px", true);
else
window.open(URL, parent, "height=" + height + ",width=" + width + ",status=0,toolbar=no,menubar=no,location=no,scrollbars=yes,top=" + loc_y + ",left=" + loc_x + ",resizable=yes,modal=yes,dependent=yes,dialog=yes,minimizable=no", true);
}
function AddUser(inputid) { URL = "user.aspx?inputid=" + inputid;
loc_y = loc_x = 200;
height = 450;
if (is_ie) {
loc_x = document.body.scrollLeft + event.clientX - 100;
loc_y = document.body.scrollTop + event.clientY + 100;
height += 50;
}
LoadDialogWindow(URL, self, loc_x, loc_y, 550, height); //这里设置窗口的宽度和高度
}
//获取父窗口值
function getUserName(inputid) {
if (is_ie)
return window.dialogArguments.document.getElementsByName(inputid)[0].value;
else
return window.parent.opener.document.getElementById(inputid).value;
}
//设置父窗口值
function setUserName(inputid, users) {
if (is_ie)
window.dialogArguments.document.getElementsByName(inputid)[0].value = users;
else
window.parent.opener.document.getElementById(inputid).value = users;
} try { document.execCommand("BackgroundImageCache", false, true); } catch (e) { }
var popUpWin;
function PopUpCenterWindow(URLStr, width, height, newWin, scrollbars) {
var popUpWin = 0;
if (typeof (newWin) == "undefined") {
newWin = false;
}
if (typeof (scrollbars) == "undefined") {
scrollbars = 0;
}
if (typeof (width) == "undefined") {
width = 800;
}
if (typeof (height) == "undefined") {
height = 600;
}
var left = 0;
var top = 0;
if (screen.width >= width) {
left = Math.floor((screen.width - width) / 2);
}
if (screen.height >= height) {
top = Math.floor((screen.height - height) / 2);
}
if (newWin) {
open(URLStr, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');
return;
} if (popUpWin) {
if (!popUpWin.closed) popUpWin.close();
}
popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');
popUpWin.focus();
} function OpenModelWindow(url, option) {
var fun;
try {
if (parent != null && parent.$ != null && parent.$.ShowIfrmDailog != undefined) {
fun = parent.$.ShowIfrmDailog
}
else {
fun = $.ShowIfrmDailog;
}
}
catch (e) {
fun = $.ShowIfrmDailog;
}
fun(url, option);
}
function CloseModelWindow(callback, dooptioncallback) {
parent.$.closeIfrm(callback, dooptioncallback);
}
function StrFormat(temp, dataarry) {
return temp.replace(/\{([\d]+)\}/g, function(s1, s2) { var s = dataarry[s2]; if (typeof (s) != "undefined") { if (s instanceof (Date)) { return s.getTimezoneOffset() } else { return encodeURIComponent(s) } } else { return "" } });
}
function StrFormatNoEncode(temp, dataarry) {
return temp.replace(/\{([\d]+)\}/g, function(s1, s2) { var s = dataarry[s2]; if (typeof (s) != "undefined") { if (s instanceof (Date)) { return s.getTimezoneOffset() } else { return (s); } } else { return ""; } });
}
function getiev() {
var userAgent = window.navigator.userAgent.toLowerCase();
$.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
$.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
$.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
var v;
if ($.browser.msie8) {
v = 8;
}
else if ($.browser.msie7) {
v = 7;
}
else if ($.browser.msie6) {
v = 6;
}
else { v = -1; }
return v;
}
$(document).ready(function() {
var v = getiev()
if (v > 0) {
$(document.body).addClass("ie ie" + v);
} });