js获取当前地址 js获取当前url实例代码

发布时间:2020-09-19编辑:脚本学堂
本文介绍了js获取当前地址,以及js获取当前url的实现代码,有需要的朋友参考下。

在js编程中,如何获取当前地址,如何获取当前url地址内容,本节分享一例代码,大家做个参考。

例子:
 

复制代码 代码示例:
<table width=100% cellpadding=0 cellspacing=0 border=0 >
<script language="javascript">
thisurl = document.url;
thishref = document.location.href;
thissloc = self.location.href;
thisdloc = document.location;
strwrite = "<tr><td valign=top>thisurl: </td><td>[" + thisurl + "]</td></tr>"
strwrite += "<tr><td valign=top>thishref: </td><td>[" + thishref + "]</td></tr>"
strwrite += "<tr><td valign=top>thissloc: </td><td>[" + thissloc + "]</td></tr>"
strwrite += "<tr><td valign=top>thisdloc: </td><td>[" + thisdloc + "]</td></tr>"
document.write( strwrite );
</script> (脚本学堂 www.jb200.com 编辑整理)
thisdloc = document.location; <br>
thisurl = document.url; <br>
thishref = document.location.href; <br>
thissloc = self.location.href;<br>
<script language="javascript">
thistloc = top.location.href;
thisploc = parent.document.location;
thisthost = top.location.hostname;
thishost = location.hostname;
strwrite = "<tr><td valign=top>thistloc: </td><td>[" + thistloc + "]</td></tr>"
strwrite += "<tr><td valign=top>thisploc: </td><td>[" + thisploc + "]</td></tr>"
strwrite += "<tr><td valign=top>thisthost: </td><td>[" + thisthost + "]</td></tr>"
strwrite += "<tr><td valign=top>thishost: </td><td>[" + thishost + "]</td></tr>"
document.write( strwrite );
</script>
thistloc = top.location.href; <br>
thisploc = parent.document.location; <br>
thisthost = top.location.hostname; <br>
thishost = location.hostname;<br>
<script language="javascript">
tmphpage = thishref.split( "/" );
thishpage = tmphpage[ tmphpage.length-1 ];
tmpupage = thisurl.split( "/" );
thisupage = tmpupage[ tmpupage.length-1 ];
strwrite = "<tr><td valign=top>thishpage: </td><td>[" + thishpage + "]</td></tr>"
strwrite += "<tr><td valign=top>thisupage: </td><td>[" + thisupage + "]</td></tr>"
document.write( strwrite );
</script><tr><td>