javascript location 对象属性:javascript
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);
参数含义:
location.reload 实例演示
javascript的navigator 对象
navigator -- navigator对象一般用于检测浏览器与操做系统的版本
javascript navigator 对象属性:数组
navigator
.
cookieEnabled
;
navigator
.
userAgent
;
navigator中最重要的是userAgent属性,返回包含浏览器版本等信息的字符串,其次cookieEnabled也很重要,使用它能够判断用户浏览器是否开启cookie。浏览器
javascript的screen 对象
screen -- screen对象用于获取用户的屏幕信息
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/