各バージョンのブラウザでwindow.close()を使うと互換性があります.
12997 ワード
Googleとファイアフォックスのブラウザの下で、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」).
window.locations.href='about:blank'
window.close()
} else{
window.opener=null;
window.open('',''self');
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」).
window.locations.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');
}
});
});