javascript 中的location.pathname
来源:互联网 发布:巴黎 知乎 编辑:程序博客网 时间:2024/06/04 20:12
location.pathname: 返回URL的域名(域名IP)后的部分。
例如 http://www.example.com/wordpress/返回/wordpress/,
又或则 http://127.0.0.1/index.html 返回/index.html,
注意是带url的域名或域名IP
在磁盘上随便建个Html文件进行location.pathname测试,如浏览器上的路径是: C:\Documents and Settings\Administrator\桌面\testjs.html, 这样,得到的结果是: /C:\Documents and Settings\Administrator\桌面\testjs.html
既然提到这了,那我们就分析下下面的URL:
http://www.example.com:8080/test.php?user=admin&pwd=admin#login
想得到整个如上的完整url,我们用:location.href;
得到传输协议http:,我们用:location.protocol;
得到主机名连同端口www.example.com:8080,我们用:location.host;
得到主机名www.joymood.cn,我们用:location.hostname;
得到主机后部分不包括问号?后部分的/test.php,就用我们刚才讲的:location.pathname;
得到url中问号?之后井号#之前的部分?user=admin&pwd=admin,我们就用: location.search;
得到#之前的部分#login,我们就用location.hash
如上,我们可以通过location对象的某些属性得到一个完整URL的各个部分。
http://hi.baidu.com/xiaoxie336l/item/8628a634fdc3a5d996f88d70
this.getContextPath = function() {
var path;
if(location.pathname.indexOf("/")==0){
path=location.pathname.substring(1);
}else{
path=location.pathname;
}
var index=path.indexOf("/");
var contextPath="/"+path.substring(0,index);
return contextPath;
}
- javascript 中的location.pathname
- javascript 中的location.pathname
- javascript 中的location.pathname
- js中的location的href和pathname,search
- javascript中的location属性
- javascript 中的location
- 关于javascript中的location
- location.href/location.search/location.pathname区别及用法
- location.href/location.search/location.pathname区别及用法
- js 中用 location.pathname 获取项目名
- javascript中的window.location和document.location
- javascript中的location和history
- JavaScript中的Location地址对象
- javascript 中的location地址信息
- javascript中的location用法简单介绍
- javascript中的window.location.search方法
- 认识Javascript中的Location对象(一)
- javascript中的window.location.search方法简介
- 一棵以节点i为根的、大小为n的子树上,i节点的子树大小至多为2n/3(最坏情:底层恰好半满的时候)
- HTML Web Server扫盲
- 在VS2005中安装BOOST库
- eclipse编译器错误、警告设置
- mac 下实现双击打开leo文件
- javascript 中的location.pathname
- Tomcat服务器
- POJ 3468 A Simple Problem with Integers Splay
- 3.10/11--java的日子
- Eclipse开发环境搭建
- 20130310
- 润乾报表设计器使用心得
- java面向对象
- 实用的Log打印类封装,助尼快速定位源码(android)