博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Javascrip中获取页面路径
阅读量:7236 次
发布时间:2019-06-29

本文共 1217 字,大约阅读时间需要 4 分钟。

1.获取当前完整网址

<script type="text/javascript">    
thisURL = document.URL; 
thisHREF = document.location.href; 
thisSLoc = self.location.href; 
thisDLoc = document.location; 
strwrite = " thisURL: [" + thisURL + "]<br />" 
strwrite += " thisHREF: [" + thisHREF + "]<br />" 
strwrite += " thisSLoc: [" + thisSLoc + "]<br />" 
strwrite += " thisDLoc: [" + thisDLoc + "]<br />" 
document.write( strwrite ); 
</script>

2.获取当前域名信息

<script type="text/javascript">

thisTLoc = top.location.href; 

thisPLoc = parent.document.location; 
thisTHost = top.location.hostname; 
thisHost = location.hostname; 
strwrite = " thisTLoc: [" + thisTLoc + "]<br />" 
strwrite += " thisPLoc: [" + thisPLoc + "]<br />" 
strwrite += " thisTHost: [" + thisTHost + "]<br />" 
strwrite += " thisHost: [" + thisHost + "]<br />" 
document.write( strwrite ); 
</script>

3.获取当前页面

<script type="text/javascript">
tmpHPage = thisHREF.split( "/" ); 
thisHPage = tmpHPage[ tmpHPage.length-1 ]; 
tmpUPage = thisURL.split( "/" ); 
thisUPage = tmpUPage[ tmpUPage.length-1 ]; 
strwrite = " thisHPage: [" + thisHPage + "]<br />" 
strwrite += " thisUPage: [" + thisUPage + "]<br />" 
document.write( strwrite ); 
</script>

本文转自 韬光星夜 51CTO博客,原文链接:http://blog.51cto.com/xfqxj/477074,如需转载请自行联系原作者

你可能感兴趣的文章
扩展功能==继承?
查看>>
HDU 4355 Party All the Time(三分|二分)
查看>>
算法笔记_223:打印回型嵌套(Java)
查看>>
Linux环境thinkphp配置以及数据源驱动改动
查看>>
C语言之基本算法11—牛顿迭代法求平方根
查看>>
Concurrency and Application Design
查看>>
vuethink 在本地没问题,在服务器报错 , php5.6与php5.5之间的大坑
查看>>
11.使用 package.json
查看>>
idea如何设置类头注释和方法注释
查看>>
白盒测试目录导航
查看>>
linux过滤旧文件中的空行和注释行剩余内容组成新文件
查看>>
[LeetCode] Preimage Size of Factorial Zeroes Function 阶乘零的原像个数函数
查看>>
GraphQL入门1
查看>>
C#委托的介绍(delegate、Action、Func、predicate)
查看>>
巧用Scrum与Kanban
查看>>
半自动化搭建Data Guard的想法和实践(一)
查看>>
巧用flashback database实现灵活的数据回滚
查看>>
oracle 11.2.0.1 for windows server2008r2告警ORA-03137
查看>>
Excel设置下拉菜单并隐藏下拉菜单来源单元格内容
查看>>
腾讯 Bugly for Xamarin Android 的插件
查看>>