javascript---location对象、navigator对象、screen对象以及他们的属性;

javascript location 对象属性:javascript

location对象属性

location.href -- 返回或设置当前文档的URL,href是location最重要的属性,用于获取当前文档的URL或设置URL。若是设置URL,将导航到新的页面。php


将导航到梦之都首页.

函数说明:使用这种方式导航,新页面的地址将被加入history的地址列表中,所以能够使用back或go函数导航。
     assign函数在设置URL时与location.href具备彻底相同的功能。
     能够使用replace函数,它将新页面的地址在history的地址列表中删除,所以使用back或go函数没法导航。
语法:location.href="http://www.dreamdu.com/";

示例

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript href DEMO</title>
</head>
<body>
<script type="text/javascript">
document.writeln(location.href);
</script>
<input type="button" value="click here,you will navigate to the page http://www.dreamdu.com/" onclick="location.href='http://www.dreamdu.com/';" />html

</body>
</html>java

location.href 实例演示
location.pathname -- 返回URL的域名后的部分。例如 http://www.dreamdu.com/xhtml/ 返回/xhtml/
location.port -- 返回URL中的端口部分。例如 http://www.dreamdu.com:8080/xhtml/ 返回8080
location.protocol -- 返回URL中的协议部分。例如 http://www.dreamdu.com:8080/xhtml/ 返回(//)前面的内容http:

location.search -- 返回URL中的查询字符串部分。例如 http://www.dreamdu.com/dreamdu.php?id=5&name=dreamdu 返回包括(?)后面的内容?id=5&name=dreamdu

location.assign -- 设置当前文档的URL
  语法:location.assign(url);
  location.assign 实例演示

location.replace -- 设置当前文档的URL,而且在history对象的地址列表中移除这个URL
  语法:location.replace(url);
  replace函数说明:replace函数在设置URL方面与location的href属性或assign函数彻底同样,可是它会删除history对象的地址列表中的URL,从而使go或back等函数没法导航。
location.reload -- 重载当前页面
  语法:location.reload(isServer);

  参数含义:
  • isServer -- true时从服务器端从新下载页面,不然只从本地浏览器缓存中重载
  • 不使用参数时,默认为false,从本地浏览器缓存中重载
  location.reload 实例演示

j
avascript的navigator 对象

 navigator -- navigator对象一般用于检测浏览器与操做系统的版本 
  • navigator对象是window对象的属性
  • 因为navigator没有统一的标准,所以各个浏览器都有本身不一样的navigator版本,这里只介绍最广泛支持且最经常使用的

javascript navigator 对象属性:数组

  • appCodeName -- 浏览器代码名的字符串表示
  • appName -- 官方浏览器名的字符串表示
  • appVersion -- 浏览器版本信息的字符串表示
  • cookieEnabled -- 若是启用cookie返回true,不然返回falsejavaEnabled -- 若是启用java返回true,不然返回false
    •   navigator.cookieEnabled -- 返回浏览器是否支持(启用)cookie
    • 语法: navigator.cookieEnabled;
    • 一般能够在浏览器的临时文件夹中保存一个文件,此文件能够包含用户信息(好比浏览过什么页面,是否选择了自动登陆)等,这个文件被称做cookie,经过cookieEnabled属性能够判断浏览器是否启用了此功能
  • platform -- 浏览器所在计算机平台的字符串表示
  • plugins -- 安装在浏览器中的插件数组
  • taintEnabled -- 若是启用了数据污点返回true,不然返回false
  • userAgent -- 用户代理头的字符串表示
    •   navigator.userAgent -- 返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)
    • 语法 : navigator.userAgent;

navigator中最重要的是userAgent属性,返回包含浏览器版本等信息的字符串,其次cookieEnabled也很重要,使用它能够判断用户浏览器是否开启cookie。浏览器

javascript的screen 对象

screen -- screen对象用于获取用户的屏幕信息
  • screen对象是window对象的属性
  • JavaScript availHeight 属性 -- 窗口能够使用的屏幕高度,单位像素
  • JavaScript availWidth 属性 -- 窗口能够使用的屏幕宽度,单位像素JavaScript colorDepth 属性 -- 用户浏览器表示的颜色位数,一般为32位(每像素的位数)
  • JavaScript pixelDepth 属性 -- 用户浏览器表示的颜色位数,一般为32位(每像素的位数)(IE不支持此属性)
  • JavaScript height 属性 -- 屏幕的高度,单位像素
  • JavaScript width 属性 -- 屏幕的宽度,单位像素

availWidth与availHeight属性很是有用,例如:能够使用下面的代码填充用户的屏幕:缓存

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript screen 对象窗口最大化示例 </title>
</head>
<body>
<script type="text/javascript">
window.moveTo(0,0);
window.resizeTo(screen.availWidth, screen.availHeight);
</script>服务器

 

</body>
</html>cookie


更多javascript资料:http://www.dreamdu.com/javascript/exe_all/
相关文章
相关标签/搜索