<html> <head> <title> 测试navigator对象 </title> <body> <script> document.write("navigator.appName="+navigator.appName); document.write("<br>"); document.write("parseFloat(navigator.appVersion)="+parseFloat(navigator.appVersion)); document.write("<br>appVersion属性返回一串包含比版本号更多的信息字符,但现在我们只要版本号。要从字符串中提出版本号我们使用一个叫parseFloat()的函数来返回数字。"); document.write("navigator.appVersion="+parseFloat(navigator.appVersion)); document.write("<br>"); 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>") document.write("navigator对象的方法"+"<br>") document.write("1.javaEnabled():"+navigator.javaEnabled()+"</br>") 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("this browser is not 4.0 compliant.<br>") } else{ document.write("you are using a version 4.0compatible browser")} document.write("location对象的属性"+"<br>") document.write("1.hash"+location.hash+"<br>") document.write("2.hostname"+location.hostname+"<br>") document.write("3.host"+location.host+"<br>") document.write("4.href:"+location.href+"<br>") document.write("5.port:"+location.port+"<br>") document.write("6.search"+location.search+"<br>") </script> </body> </html>
结果:
navigator.appName=Microsoft Internet Explorer
parseFloat(navigator.appVersion)=4
appVersion属性返回一串包含比版本号更多的信息字符,但现在我们只要版本号。要从字符串中提出版本号我们使用一个叫parseFloat()的函数来返回数字。navigator.appVersion=4
navigator 对象的属性:
appcodename:Mozilla
appname::Microsoft Internet Explorer
appversion:4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
platform:Win32
userAgent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
navigator对象的方法
1.javaEnabled():true
用户浏览器是微软的IE浏览器
this browser is not 4.0 compliant.
location对象的属性
1.hash
2.hostname
3.host
4.href:file:///C:/Documents%20and%20Settings/Administrator/桌面/openHTML.html
5.port:
6.search