里介绍几个javascript常用的函数,javascript大小写转换、javascript重定向页面、javascript判断浏览器。
js大小写转化
JavaScript把小写字母转化成大写字母:toUpperCase
js重定向页面
如果要在本窗口中重定向:self.location="url地址"
如果要在新窗口中打开的话:window.open(url地址)
js判断浏览器
js大小写转化
JavaScript把小写字母转化成大写字母:toUpperCase
//
toUpperCase用法:
var strVar = " This is a STRING! " ;
strVariable = strVar.toUpperCase();
// strVariable结果为:THIS IS A STRING!
JavaScript把大写字母转化成小写字母:toLowerCase
// toLowerCase用法:
var strVar = " This is a STRING! " ;
strVariable = strVar.toLowerCase();
// strVariable结果为:this is a string!
var strVar = " This is a STRING! " ;
strVariable = strVar.toUpperCase();
// strVariable结果为:THIS IS A STRING!
JavaScript把大写字母转化成小写字母:toLowerCase
// toLowerCase用法:
var strVar = " This is a STRING! " ;
strVariable = strVar.toLowerCase();
// strVariable结果为:this is a string!
如果要在本窗口中重定向:self.location="url地址"
如果要在新窗口中打开的话:window.open(url地址)
js判断浏览器
<
script language
=
"
JavaScript
"
>
<!--
function getOs()
{
var OsObject = "" ;
if (navigator.userAgent.indexOf( " MSIE " ) > 0 ) {
return " MSIE " ;
}
if (isFirefox = navigator.userAgent.indexOf( " Firefox " ) > 0 ){
return " Firefox " ;
}
if (isSafari = navigator.userAgent.indexOf( " Safari " ) > 0 ) {
return " Safari " ;
}
if (isCamino = navigator.userAgent.indexOf( " Camino " ) > 0 ){
return " Camino " ;
}
if (isMozilla = navigator.userAgent.indexOf( " Gecko/ " ) > 0 ){
return " Gecko " ;
}
}
alert( " 您的浏览器类型为: " + getOs());
-->
</ script >
<!--
function getOs()
{
var OsObject = "" ;
if (navigator.userAgent.indexOf( " MSIE " ) > 0 ) {
return " MSIE " ;
}
if (isFirefox = navigator.userAgent.indexOf( " Firefox " ) > 0 ){
return " Firefox " ;
}
if (isSafari = navigator.userAgent.indexOf( " Safari " ) > 0 ) {
return " Safari " ;
}
if (isCamino = navigator.userAgent.indexOf( " Camino " ) > 0 ){
return " Camino " ;
}
if (isMozilla = navigator.userAgent.indexOf( " Gecko/ " ) > 0 ){
return " Gecko " ;
}
}
alert( " 您的浏览器类型为: " + getOs());
-->
</ script >