javascript 中使用navigator对象

使用navigator   

1.使用navigator对象   

<script>  
document.write(
"navigator对象的属性"+"<br>")  
document.write(
"appcodename:"+navigator.appCodeName+"<br>")  
document.write(
"appname::"+navigator.appName+"<br>")  
document.write(
"appversion:"+navigator.appVersion+"<br>")  
document.write(
"platform:"+navigator.platform+"<br>")  
document.write(
"userAgent:"+navigator.userAgent+"<br>")  
</script>  
<script>  
document.write(
"navigator对象的方法"+"<br>")  
document.write(
"javaEnabled():"+navigator.javaEnabled())  
</script>   

2.检查用户的浏览器   

<script>  
if(navigator.appName.indexOf("Microsoft")!=-1){  
document.write(
"用户浏览器是微软的IE浏览器"+"<br>")}
  
else if(navigator.appName.indexOf("Netscape")!=-1){  
document.write(
"用户浏览器是netscape的netscape浏览器"+"<br>")}
  
if(navigator.appVersion.indexOf("4.0")!=-1){  
document.write(
"you are using a version 4.0compatible browser")  
}
  
else{  
document.write(
"this browser is not 4.0 compliant")}
  
</script>   

3.检测用户的操作系统   

<script>  
if (navigator.platform.indexOf("win32")!=-1){  
document.write(
"you are using a computer running windows 95 or highter")}
  
else{  
document.write(
"this computer is not running windows 95 or higher")}
  
</script>   

4.使用location对象   

<script>  
document.write(
"location对象的属性"+"<br>")  
document.write(
"hash"+location.hash+"<br>")  
document.write(
"hostname"+location.hostname+"<br>")  
document.write(
"host"+location.host+"<br>")  
document.write(
"href"+location.href+"<br>")  
document.write(
"port"+location.port+"<br>")  
document.write(
"search"+location.search+"<br>")  
</script>   

重新加载网页  
<form name=form1>  
<input type=button name=button1 value=重新加载本页 onclick=location.reload>  
</form>   

5.使用cookie   

<script>  
finction makecookie()
{  
if(!document.cookie){  
name
=prompt("请输入你的姓名");  
document.cookie
="name="+name+";";}
  
}
  
</script>   

<body onload=makecookie()>  
<script>  
function makecookie(){  
if(!document.cookie){  
name
=prompt("请输入你的姓名")  
document.cookie
="name="+name+";";  
namestart
=document.cookie.indexOf("=");  
nameend
=document.cookieindexOf(";");  
document.writeln(
"your name is:" 
+document.cookie.substring(namestart+1,nameend)+",br>")  
}
  
}
  
</script>  

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值