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

  1 /// <reference path="intellisense/jquery-1.2.6-vsdoc.js" />
  2 var userAgent = navigator.userAgent.toLowerCase();
  3 var is_opera = userAgent.indexOf(‘opera‘) != -1 && opera.version();
  4 var is_moz = (navigator.product == ‘Gecko‘) && userAgent.substr(userAgent.indexOf(‘firefox‘) + 8, 3);
  5 var ua_match = /(trident)(?:.*rv:([\w.]+))?/.exec(userAgent) || /(msie) ([\w.]+)/.exec(userAgent);
  6 var is_ie = ua_match && (ua_match[1] == ‘trident‘ || ua_match[1] == ‘msie‘) ? true : false;
  7 
  8 function LoadDialogWindow(URL, parent, loc_x, loc_y, width, height) {
  9     if (is_ie)//window.open(URL);
 10         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);
 11     else
 12         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);
 13 }
 14 function AddUser(inputid) {
 15 
 16     URL = "user.aspx?inputid=" + inputid;
 17     loc_y = loc_x = 200;
 18     height = 450;
 19     if (is_ie) {
 20         loc_x = document.body.scrollLeft + event.clientX - 100;
 21         loc_y = document.body.scrollTop + event.clientY + 100;
 22         height += 50;
 23     }
 24     LoadDialogWindow(URL, self, loc_x, loc_y, 550, height); //这里设置窗口的宽度和高度
 25 }
 26 //获取父窗口值
 27 function getUserName(inputid) {
 28     if (is_ie)
 29         return window.dialogArguments.document.getElementsByName(inputid)[0].value;
 30     else
 31         return window.parent.opener.document.getElementById(inputid).value;
 32 }
 33 //设置父窗口值
 34 function setUserName(inputid, users) {
 35     if (is_ie)
 36         window.dialogArguments.document.getElementsByName(inputid)[0].value = users;
 37     else
 38         window.parent.opener.document.getElementById(inputid).value = users;
 39 }
 40 
 41 try { document.execCommand("BackgroundImageCache", false, true); } catch (e) { }
 42 var popUpWin;
 43 function PopUpCenterWindow(URLStr, width, height, newWin, scrollbars) {
 44     var popUpWin = 0;
 45     if (typeof (newWin) == "undefined") {
 46         newWin = false;
 47     }
 48     if (typeof (scrollbars) == "undefined") {
 49         scrollbars = 0;
 50     }
 51     if (typeof (width) == "undefined") {
 52         width = 800;
 53     }
 54     if (typeof (height) == "undefined") {
 55         height = 600;
 56     }
 57     var left = 0;
 58     var top = 0;
 59     if (screen.width >= width) {
 60         left = Math.floor((screen.width - width) / 2);
 61     }
 62     if (screen.height >= height) {
 63         top = Math.floor((screen.height - height) / 2);
 64     }
 65     if (newWin) {
 66         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 + ‘‘);
 67         return;
 68     }
 69 
 70     if (popUpWin) {
 71         if (!popUpWin.closed) popUpWin.close();
 72     }
 73     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 + ‘‘);
 74     popUpWin.focus();
 75 }
 76 
 77 function OpenModelWindow(url, option) {
 78     var fun;
 79     try {
 80         if (parent != null && parent.$ != null && parent.$.ShowIfrmDailog != undefined) {
 81             fun = parent.$.ShowIfrmDailog
 82         }
 83         else {
 84             fun = $.ShowIfrmDailog;
 85         }
 86     }
 87     catch (e) {
 88         fun = $.ShowIfrmDailog;
 89     }
 90     fun(url, option);
 91 }
 92 function CloseModelWindow(callback, dooptioncallback) {
 93     parent.$.closeIfrm(callback, dooptioncallback);
 94 }
 95 function StrFormat(temp, dataarry) {
 96     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 "" } });
 97 }
 98 function StrFormatNoEncode(temp, dataarry) {
 99     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 ""; } });
100 }
101 function getiev() {
102     var userAgent = window.navigator.userAgent.toLowerCase();
103     $.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
104     $.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
105     $.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
106     var v;
107     if ($.browser.msie8) {
108         v = 8;
109     }
110     else if ($.browser.msie7) {
111         v = 7;
112     }
113     else if ($.browser.msie6) {
114         v = 6;
115     }
116     else { v = -1; }
117     return v;
118 }
119 $(document).ready(function() {
120     var v = getiev()
121     if (v > 0) {
122         $(document.body).addClass("ie ie" + v);
123     }
124 
125 });
126   

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。