location对象

Location 对象包含有关当前 URL 的信息。

Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。

属性描述IEFO
hash 设置或返回从井号 (#) 开始的 URL(锚)。 4 1 9
host 设置或返回主机名和当前 URL 的端口号。 4 1 9
hostname 设置或返回当前 URL 的主机名。 4 1 9
href 设置或返回完整的 URL。 4 1 9
pathname 设置或返回当前 URL 的路径部分。 4 1 9
port 设置或返回当前 URL 的端口号。 4 1 9
protocol 设置或返回当前 URL 的协议。 4 1 9
search 设置或返回从问号 (?) 开始的 URL(查询部分)。 4 1 9

例子:

document.write(location.href + "<br />");//http://localhost/smarty/fpage.php?p=6
document.write(location.host + "<br />");//localhost:8080
document.write(location.hostname + "<br />");//localhost
document.write(location.hash + "<br />");//#dada
document.write(location.search + "<br />");//?p=6
document.write(location.pathname + "<br />");// /smarty/fpage.php
document.write(location.protocol + "<br />");//http:
document.write(location.port + "<br />");//8080

 

 

 

posted @ 2013-07-05 22:19  snowinmay  阅读(227)  评论(0编辑  收藏  举报