javascript和jquery如何获取当前页面的url
按照地址为: http://www.abshu.com:8082/index.php#tab2?foo=123 为例
Javascript:
代码 返回 -------------------------------------------------------------------------- window.location.host www.abshu.com:8082 window.location.hostname www.abshu.com window.location.port 8082 window.location.protocol http window.location.pathname index.php window.location.href http://www.abshu.com:8082/index.php#tab2 window.location.hash #tab2 window.location.search ?foo=123
Jquery:
代码 返回
--------------------------------------------------------------------------
$(location).attr('host'); www.test.com:8082
$(location).attr('hostname'); www.test.com
$(location).attr('port'); 8082
$(location).attr('protocol'); http
$(location).attr('pathname'); index.php
$(location).attr('href'); http://www.test.com:8082/index.php#tab2
$(location).attr('hash'); #tab2
$(location).attr('search'); ?foo=123
本文介绍如何使用JavaScript和jQuery获取当前页面的各种URL相关信息,包括主机地址、路径名、完整URL等,并通过实例进行说明。
1270

被折叠的 条评论
为什么被折叠?



