当前位置:首页>网络学院>网页制作>Javascript教程>文章内容

Javascript获得当前网页地址的几种方法

[ 来源:http://www.it55.com | 作者: | 时间:2007-10-08 | 收藏 | 推荐 ] 【

Javascript获得当前网页地址的几种方法,以下几种方法因其实现目的不同而各有异同: 免费壁纸下载http://www.it55.com

设置或获取对象指定的文件名或路径。
<script>
alert(window.location.pathname)
</script>

IT资讯之家 http://www.it55.com

设置或获取整个 URL 为字符串。
<script> 免费网页模版下载http://www.it55.com

alert(window.location.href);
</script>
设置或获取与 URL 关联的端口号码。
<script>
alert(window.location.port)
</script>

http://www.it55.com/

设置或获取 URL 的协议部分。
<script>
alert(window.location.protocol)
</script> 45398 http://www.it55.com it55学习IT知识,享受IT生活 4dfkjn

设置或获取 href 属性中在井号“#”后面的分段。
<script>
alert(window.location.hash)
</script> 免费网页模版下载http://www.it55.com

设置或获取 location 或 URL 的 hostname 和 port 号码。
<script>
alert(window.location.host)
</script>

IT资讯之家 http://www.it55.com

设置或获取 href 属性中跟在问号后面的部分。
<script>
alert(window.location.search)
</script> 45398 http://www.it55.com it55学习IT知识,享受IT生活 4dfkjn

(编辑:IT资讯之家 www.it55.com

返回顶部
 

网友评论

[以下评论为网友观点,不代表本站。请自觉遵守互联网相关政策法规,所有连带责任均有评论者自负。]
[不超过250字]

图片文章