Javascript脚本:Location 对象
Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。
举例说下 Location 对象 的属性与方法

  1. hash:设置或返回从井号 (#) 开始的 URL(锚)
  2. 网址:http://www.cngothic.com/index.html#head
  3. 返回:#head
  4. <script type="text/javascript">
  5. document.write(location.pathname);
  6. </script>
  7.  
  8. host:设置或返回主机名和当前 URL 的端口号
  9. 网址:http://www.cngothic.com:3389/index.html
  10. 返回:www.cngothic.com:3389
  11.  
  12. hostname:设置或返回当前 URL 的主机名
  13. 网址:http://www.cngothic.com:3389/index.html
  14. 返回:www.cngothic.com
  15.  
  16. href:设置或返回完整的 URL
  17. 网址:http://www.cngothic.com:3389/index.html
  18. 返回:http://www.cngothic.com:3389/index.html
  19.  
  20. pathname:设置或返回当前 URL 的路径部分
  21. 网址:http://www.cngothic.com/index.html#head
  22. 返回:/index.html
  23.  
  24. port:设置或返回当前 URL 的端口号
  25. 网址:http://www.cngothic.com:3389/index.html
  26. 返回:3389
  27.  
  28. protocol:设置或返回当前 URL 的协议
  29. 网址:http://www.cngothic.com:3389/index.html
  30. 返回:http:
  31.  
  32. search:设置或返回从问号 (?) 开始的 URL(查询部分)。
  33. 网址:http://www.cngothic.com/index.html?id=333
  34. 返回:?id=333

  1. assign():加载新的文档
  2. 语法:window.location.assign(URL)
  3.  
  4. reload():重新加载当前文档
  5. 语法:window.location.reload()
  6.  
  7. replace():用新的文档替换当前文档
  8. 语法:window.location.replace()

, , , , , , , , , , ,

Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

Leave a reply?

Logged in as cngothic. Logout »