//Javascript获取站点获得根目录绝对路径 function getRootPath() { //完整路径 var strFullPath = window.document.location.href; //相对路径 var strPath = window.document.location.pathname; //完整路径-相对路径=Http://域名 var pos = strFullPath.indexOf(strPath); var prePath = strFullPath.substring(0, pos); //将相对路径掐头去尾 var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1); //得到最终的路径 return (prePath + postPath); }
也是好长时间没来了,作为一个业余的还真是没有时间保障啊!
本文介绍了一种使用JavaScript获取网站根目录绝对路径的方法,通过分析URL和路径,实现跨域资源请求的基础路径定位。
819

被折叠的 条评论
为什么被折叠?



