js 获取当前页面的url等内容 window.location系列
2015-10-27 15:01
776 查看
设置或获取对象指定的文件名或路径。
alert(window.location.pathname)
设置或获取整个 URL 为字符串。
alert(window.location.href);
设置或获取与 URL 关联的端口号码。
alert(window.location.port)
设置或获取 URL 的协议部分。
alert(window.location.protocol)
设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash)
设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host)
设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search)
获取变量的值(截取等号后面的部分)
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
实际案例为:http://baike.haosou.com/doc/1824927-1930028.html
alert(window.location.pathname)
设置或获取整个 URL 为字符串。
alert(window.location.href);
设置或获取与 URL 关联的端口号码。
alert(window.location.port)
设置或获取 URL 的协议部分。
alert(window.location.protocol)
设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash)
设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host)
设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search)
获取变量的值(截取等号后面的部分)
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
实际案例为:http://baike.haosou.com/doc/1824927-1930028.html
相关文章推荐
- JS toString的新用法
- js获取url传递参数
- 在Ext JS 5应用程序中如何使用路由
- js 获取月份 格式yy-mm-dd
- javascript 函数也是数据类型
- jstl标签库的使用
- javascript 学习总结(四)Date对象
- JS判断智能机
- 常规功能和模块自定义系统 (cfcmms)—013给Extjs6加入多界面主题(Theme)
- 一段php json与javascript的交互
- 【JSOI2008】【BZOJ1012】最大数maxnumber
- javascript 学习总结(三)Boolean对象
- 自定义标签&&JSTL标签库详解
- JS replace如何替换全部字符串
- js注册检测 用户名、密码、手机号、邮箱
- JSONArray排序
- javascript 学习总结(二)Array数组
- javascript基础之十二(JavaScript的代码容器)
- javascript基础之十(基于原型实现类的继承)
- javascript基础之九(JavaScript数据封装)