JavaScript Location 对象

 

测试代码

<script type="text/javascript">

//设置或返回从井号 (#) 开始的 URL(锚)。
document.write(location.hash);	
document.write("<br>");	

//设置或返回主机名和当前 URL 的端口号。
document.write(location.host);	
document.write("<br>");	
	
//设置或返回当前 URL 的主机名。
document.write(location.hostname);	
document.write("<br>");	
	
//设置或返回完整的 URL。
document.write(location.href);	
document.write("<br>");	

//设置或返回当前 URL 的路径部分。
document.write(location.pathname);	
document.write("<br>");	

//设置或返回当前 URL 的端口号。
document.write(location.port);	
document.write("<br>");	

//设置或返回当前 URL 的协议。
document.write(location.protocol);	
document.write("<br>");	

//设置或返回从问号 (?) 开始的 URL(查询部分)。
document.write(location.search);	
document.write("<br>");	


</script>

 

访问路径

http://127.0.0.1:8080/samltest/index/test.jsp?name=hello#a/b

 

输出结果

#a/b
127.0.0.1:8080
127.0.0.1
http://127.0.0.1:8080/samltest/index/test.jsp?name=hello#a/b
/samltest/index/test.jsp
8080
http:
?name=hello

 

 

 

 

 

猜你喜欢

转载自huangqiqing123.iteye.com/blog/2378611
今日推荐