![](https://img-my.csdn.net/uploads/201212/31/1356940630_7294.jpg)
例子:
hash——
假设当前的 URL 是: http://example.com:1234/test.htm#part2:
<html>
<body>
<script type="text/javascript">
document.write(location.hash
);
</script>
</body>
</html>
输出:
#part2
实例
假设当前的 URL 是: http://example.com:1234/test.htm#part2:
<html>
<body>
<script type="text/javascript">
document.write(location.host
);
</script>
</body>
</html>
输出:
example.com:1234
实例
假设当前的 URL 是: http://example.com:1234/test.htm#part2:
<html> <body> <script type="text/javascript"> document.write(location.hostname); </script> </body> </html>
输出:
example.com
href——
实例
假设当前的 URL 是: http://example.com:1234/test.htm#part2:
<html>
<body>
<script type="text/javascript">
document.write(location.href
);
</script>
</body>
</html>
输出:
http://example.com:1234/test.htm#part2
pathname——
实例
假设当前的 URL 是: http://example.com:1234/test/test.htm#part2:<html> <body> <script type="text/javascript"> document.write(location.pathname); </script> </body> </html>
输出:
/test/test.htm