javascript javascript的一些帮助:如broswer检测或协议检测,并打开一个弹出窗口。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript javascript的一些帮助:如broswer检测或协议检测,并打开一个弹出窗口。相关的知识,希望对你有一定的参考价值。
function params(name) {
//return the value of params on url
// example: https://www.google.com/?name=klevis&id=456
// params('name') return 'klevis'
return (location.search.split(name + '=')[1] || '').split('&')[0];
}
function generate_iframe(parent_id,name,url,classstyle,clerar=false){
//generate a iframe from javascript or clear it
/*exmaple: generate_iframe(
'content_iframe',
'iframe_name'
'https://www.google.com',
'iframeclass',
false,
)*/
if(clear==true){
document.querySelector("#"+parent_id).innerHTML = '';
}else{
document.querySelector("#"+parent_id).innerHTML += '<iframe id="'+name+'" name="'+name+'" src="'+url+'" class="'+classstyle+'"></iframe>';
}
}
function isBroswer(name){
// dettect id is the current broswer
if(!name) return 'empty';
switch(name){
case 'chrome':
// Chrome 1+
return !!window.chrome && !!window.chrome.webstore;
break;
case 'firefox':
// Firefox 1.0+
return typeof InstallTrigger !== 'undefined';
break;
case 'ie':
var isIE = /*@cc_on!@*/false || !!document.documentMode;
return isIE;
break;
case 'edge':
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
return !isIE && !!window.StyleMedia;
break;
case 'blink':
// Blink engine detection
return (isChrome || isOpera) && !!window.CSS
break;
case 'opera':
//Opera
return (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
break;
case 'safari':
// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification));
return isSafari;
break;
default:
return null;
break;
}
}
//isBroswer('chrome') return true/false
function popUpWindow(mypage, w, h, pos, myname, infocus){
//open a pop up window
if (w!=parseInt(w)||w<=0) w=$width;
if (h!=parseInt(h)||h<=0) h=$height;
if (myname==null){myname="swin"};
var myleft = 0;
var mytop = 0;
if (myleft==0 && mytop==0 && pos!="random"){pos="center"};
if (pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if (pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=no";swin=window.open(mypage,myname,settings);
if (infocus==null || infocus=="front"){swin.focus()};
return false;
}
//popUpWindow(url, 400, 400, 'center', 'Name Of Window', 'front');
function protocol(partname){
// return true or false the current page protocol
if(partname) partname = partname+':';
if( window.location.protocol == partname ){
return true
}else return false
}
//protocol('file|http|https') return true | false
以上是关于javascript javascript的一些帮助:如broswer检测或协议检测,并打开一个弹出窗口。的主要内容,如果未能解决你的问题,请参考以下文章