各个版本浏览器下使用window.close()兼容问题

          谷歌和火狐浏览器下,不能使用关闭window.close()方法关闭本页       

function exit(){

  if (navigator.userAgent.indexOf("MSIE") > 0) {
           window.opener = null;
           window.close();
       } else if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Chrome")!=-1) {
           window.location.href = 'about:blank';
           window.close();
       } else {
           window.opener = null;
           window.open('', '_self', '');
           window.close();
       }

}


完整:

	/**
	 * 浏览器类型判断
	 */
	function BROWSER() {
		var Browser_Name = navigator.appName;
		var Browser_Version = parseFloat(navigator.appVersion);
		var Browser_Agent = navigator.userAgent;
		var Actual_Version, Actual_Name;
		var is_IE = (Browser_Name == "Microsoft Internet Explorer");//判读是否为ie浏览器
		var is_NN = (Browser_Name == "Netscape");//判断是否为netscape浏览器
		var is_op = (Browser_Name == "Opera");//判断是否为Opera浏览器
		if (is_NN) {
			//upper 5.0 need to be process,lower 5.0 return directly
			if (Browser_Version >= 5.0) {
				if (Browser_Agent.indexOf("Netscape") != -1) {
					var Split_Sign = Browser_Agent.lastIndexOf("/");
					var Version = Browser_Agent.lastIndexOf(" ");
					var Bname = Browser_Agent.substring(0, Split_Sign);
					var Split_sign2 = Bname.lastIndexOf(" ");
					Actual_Version = Browser_Agent.substring(Split_Sign + 1, Browser_Agent.length);
					Actual_Name = Bname.substring(Split_sign2 + 1, Bname.length);
				}
				if (Browser_Agent.indexOf("Firefox") != -1) {
					var Version = Browser_Agent.lastIndexOf("Firefox");
					Actual_Version = Browser_Agent.substring(Version + 8, Browser_Agent.length);
					Actual_Name = Browser_Agent.substring(Version, Version + 7);
				}
				if (Browser_Agent.indexOf("Safari") != -1) {
					if (Browser_Agent.indexOf("Chrome") != -1) {
						var Split_Sign = Browser_Agent.lastIndexOf(" ");
						var Version = Browser_Agent.substring(0, Split_Sign);;
						var Split_Sign2 = Version.lastIndexOf("/");
						var Bname = Version.lastIndexOf(" ");
						Actual_Version = Version.substring(Split_Sign2 + 1, Version.length);
						Actual_Name = Version.substring(Bname + 1, Split_Sign2);
					} else {
						var Split_Sign = Browser_Agent.lastIndexOf("/");
						var Version = Browser_Agent.substring(0, Split_Sign);;
						var Split_Sign2 = Version.lastIndexOf("/");
						var Bname = Browser_Agent.lastIndexOf(" ");
						Actual_Version = Browser_Agent.substring(Split_Sign2 + 1, Bname);
						Actual_Name = Browser_Agent.substring(Bname + 1, Split_Sign);
					}
				}
				if (Browser_Agent.indexOf("Trident") != -1) {
					Actual_Version = Browser_Version;
					Actual_Name = Browser_Name;
				}
				if (Browser_Agent.indexOf("Edge") != -1) {
					var Version = Browser_Agent.lastIndexOf("Edge");
					Actual_Version = Browser_Agent.substring(Version + 5, Browser_Agent.length);
					Actual_Name = Browser_Agent.substring(Version, Version + 4);
				}
			} else {

				Actual_Version = Browser_Version;
				Actual_Name = Browser_Name;
			}
		} else if (is_IE) {
			var Version_Start = Browser_Agent.indexOf("MSIE");
			var Version_End = Browser_Agent.indexOf(";", Version_Start);
			Actual_Version = Browser_Agent.substring(Version_Start + 5, Version_End)
			Actual_Name = Browser_Name;

			if (Browser_Agent.indexOf("Maxthon") != -1 || Browser_Agent.indexOf("MAXTHON") != -1) {
				var mv = Browser_Agent.lastIndexOf(" ");
				var mv1 = Browser_Agent.substring(mv, Browser_Agent.length - 1);
				mv1 = "遨游版本:" + mv1;
				Actual_Name += "(Maxthon)";
				Actual_Version += mv1;
			}
		} else if (Browser_Agent.indexOf("Opera") != -1) {
			Actual_Name = "Opera";
			var tempstart = Browser_Agent.indexOf("Opera");
			var tempend = Browser_Agent.length;
			Actual_Version = Browser_Version;
		} else {
			Actual_Name = "Unknown Navigator"
			Actual_Version = "Unknown Version"
		}
		/*------------------------------------------------------------------------------
		 --Your Can Create new properties of navigator(Acutal_Name and Actual_Version) --
		 --Userage:                                                                     --
		 --1,Call This Function.                                                        --
		 --2,use the property Like This:navigator.Actual_Name/navigator.Actual_Version;--
		 ------------------------------------------------------------------------------*/
		navigator.Actual_Name = Actual_Name;
		navigator.Actual_Version = Actual_Version;

		/*---------------------------------------------------------------------------
		 --Or Made this a Class.                                                     --
		 --Userage:                                                                  --
		 --1,Create a instance of this object like this:var browser=new browserinfo;--
		 --2,user this instance:browser.Version/browser.Name;                        --
		 ---------------------------------------------------------------------------*/
		this.Name = Actual_Name;
		this.Version = Actual_Version;
		this.isFirefox = function () {
			if (Actual_Name.indexOf("Firefox") == -1)
				return false;
			else
				return true;
		}
		this.isSafari = function () {
			if (Actual_Name.indexOf("Safari") == -1)
				return false;
			else
				return true;
		}
		this.isChrome = function () {
			if (Actual_Name.indexOf("Chrome") == -1)
				return false;
			else
				return true;
		}
		
		//判读是否为ie6浏览器
		this.isCurrIE6 = function () {
			if (Browser_Agent.toLowerCase().indexOf("msie 6.0") != -1)
				return true;
			else
				return false;
		}
		//判读是否为ie7浏览器
		this.isCurrIE7 = function () {
			if (Browser_Agent.toLowerCase().indexOf("msie 7.0") != -1)
				return true;
			else
				return false;
		}
		//判读是否为ie8浏览器
		this.isCurrIE8 = function () {
			if (Browser_Agent.toLowerCase().indexOf("msie 8.0") != -1)
				return true;
			else
				return false;
		}
		//判读是否为ie9浏览器
		this.isCurrIE9 = function () {
			if (Browser_Agent.toLowerCase().indexOf("msie 9.0") != -1)
				return true;
			else
				return false;
		}
		//判读是否为ie11浏览器
		this.isCurrIE11 = function () {
			if ((Browser_Name == "Netscape") && (parseFloat(Browser_Version) >= 5.0) && (Browser_Agent.indexOf("Trident") != -1))
				return true;
			else
				return false;
		}
		//判读是否为ie-edge浏览器
		this.isCurrEdge = function () {
			if ((Browser_Name == "Netscape") && (Browser_Agent.indexOf("Edge") != -1))
				return true;
			else
				return false;
		}
		//判读是否为ie浏览器
		this.isIE = function () {
			if (Browser_Name != "Microsoft Internet Explorer" && !this.isCurrIE11())
				return false;
			else
				return true;
		}

	}
	
	/* 实例化BROWSER
	 * 用法:
	 * 浏览器名称:BROWSER.Name
	 * 浏览器版本:BROWSER.Version
	 * BROWSER.Name='Microsoft Internet Explorer'  //IE
	 * BROWSER.Name='Firefox'  //Firefox
	 * ……待补充
	 */
	var BROWSER = new BROWSER();
	
	/*
    初始化页面中的下拉框样式
	*/
	function initSelectCtrl() {
		$(".pbd_selectCtrl .btn_select").bind('change', function () {
			if ($(this).attr("noStflag") != "true" && $(this).children('option').length > 0) {
				if (BROWSER.isCurrIE8() || BROWSER.isCurrIE9()|| BROWSER.isSafari()) {
					//兼容IE8
					$(this).siblings(".cur_select").text($(this).children('option:selected')[0].text);
				}
				else {
					$(this).siblings(".cur_select").text($(this).children('option:selected')[0].label);
				}

			}

			//兼容因select控件的option过长导致的显示问题
			if ($(this).attr("auto-offsize") == "true") {
				$(this).css("width", "auto");
				var minOff = $(this).attr("min-offsize");
				if (minOff != null && parseInt(minOff) > 0) {
					if ($(this).width() < parseInt(minOff)) {
						$(this).css("width", parseInt(minOff));
						resizeSelectCtrl($(this).attr("id"), parseInt(minOff));
					} else {
						$(this).css("width", $(this).width());
						resizeSelectCtrl($(this).attr("id"), $(this).width());
					}
				}
			}
		});
		for (var i = 0; i < $(".pbd_selectCtrl").length ; i++) {
			var selectCtrl = $(".pbd_selectCtrl").eq(i);//
			if ($(".pbd_selectCtrl")[i].clientWidth != 298) {
				var wid_px = selectCtrl.css("width");
				var wid = parseInt(wid_px);
				selectCtrl.find(".cur_select").css("width", (wid - 28) + "px");
				selectCtrl.css("backgroundPosition", (wid - 28) + "px");
				selectCtrl.find(".btn_select").css("width", wid + "px");
			}

			if (BROWSER.isCurrIE8()) {//兼容ie8下拉框选项显示不全情况
				var wid = selectCtrl.find(".btn_select").css("width");
				selectCtrl.find(".btn_select").css("width", "auto");
				selectCtrl.find(".btn_select").css("min-width", wid);
			}
			else if (BROWSER.isSafari()) {
				//safari浏览器过窄,目前只能通过调整字体来调整宽度
				//selectCtrl.find(".btn_select").css("font-size", "18px");
				selectCtrl.find(".btn_select").css("top", "3px");
			}


			//设置默认值
			var selectOp = selectCtrl.find(".btn_select");
			if (selectOp.attr("noStflag") != "true" && selectOp.children('option').length > 0) {
				if (BROWSER.isCurrIE8() || BROWSER.isCurrIE9()|| BROWSER.isSafari()) {
					//兼容IE8
					selectOp.siblings(".cur_select").html(selectOp.children('option:selected')[0].text);
				}
				else {
					selectOp.siblings(".cur_select").html(selectOp.children('option:selected')[0].label);
				}
			}
			//tips位置
			selectCtrl.find(".tooltip").css({"margin-left":(selectCtrl.width()+10) + "px"});
		}
	}
	
	/*
    用于重新绑定下拉框的显示值
    selectId   selcect控件id
	*/
	function reBindSelectCtrl(selectId) {
	    var selectOp = $("#" + selectId);
	    //var selectOp = selectObj.find(".btn_select");
	    if (selectOp.attr("noStflag") != "true" && selectOp.children('option').length > 0) {
	        if (BROWSER.isCurrIE8() || BROWSER.isCurrIE9() || BROWSER.isSafari()) {
	            //兼容IE8
	            selectOp.siblings(".cur_select").html(selectOp.children('option:selected')[0].text);
	        }
	        else {
	            selectOp.siblings(".cur_select").html(selectOp.children('option:selected')[0].label);
	        }
	    }
	}
	
	/*
    用于设置下拉框长度(仅用于类型)
    selectId   selcect控件id
    sWidth     设置下拉框长度
	*/
	function resizeSelectCtrl(selectId, sWidth) {
	    var selectObj = $("#" + selectId);
	    var wid_px = selectObj.parent().css("width");
	    var wid = parseInt(wid_px);
	    if (wid != sWidth) {
	        wid = sWidth;
	        selectObj.siblings(".cur_select").css("width", wid-28 + "px");
	        selectObj.parent().css("backgroundPosition", (wid - 28) + "px");
	        selectObj.parent().css("width", wid + "px");
	        
	        if (BROWSER.isCurrIE8()) {//兼容ie8下拉框选项显示不全情况
	            selectObj.css("width", "auto");
	            selectObj.css("min-width", wid + "px");
	        }
	        else {
	            selectObj.css("width", wid + "px");
	        }
	    }
	
	}
	
	$(function () {
		//初始化页面中的下拉框样式
		initSelectCtrl();
		
		//radio init
		$('input[type="radio"]').each(function(i,o){
			var curRadio = $(o);
			var curLabel = $(o).parents(".ccb-radio").find('label');
			if(curRadio.is(':checked')){//checked & disabled|enable
				curLabel.attr('class', 'checked');
			} else if(curRadio.attr("disabled")){//no checked & disabled
				curLabel.attr('class', 'disabled');
			} else {
				curLabel.removeAttr('class');
			}
		});
		$(".ccb-radio label").click(function(){
			var curLabel = $(this);
			var curRadio = $(this).parents(".ccb-radio").find('input[type="radio"]');
			if(!curRadio.attr("disabled")){
				var rname = curRadio.attr("name");
				var groupRadios = $('.ccb-radio input[name="'+rname+'"]');
				curRadio.click();
				groupRadios.each(function(i, radio){
					$(radio).parents(".ccb-radio").find('label').removeAttr('class');
					$(radio).removeAttr('checked');
				});
				curLabel.attr('class', 'checked');
				curRadio.attr('checked','checked');
			}
		});
		
	});

你可能感兴趣的:(各个版本浏览器下使用window.close()兼容问题)