美文网首页
获取当前页面的绝对路径

获取当前页面的绝对路径

作者: 0尘封 | 来源:发表于2016-12-30 12:00 被阅读0次

var hosturl = window.location.href;
function abspath()
{
var abspath = unescape(window.location.href);

// Remove query String 
var index=abspath.indexOf("?");
if (index > 0) abspath = abspath.substr (0,index-1);    
    
index=abspath.lastIndexOf("/");
var index2 = abspath.lastIndexOf("\\");

index = (index > index2) ? index : index2;
if (index <= 0) return abspath;

abspath = abspath.substring(0,index);

if(abspath.substring(0,1) == "/") abspath = abspath.slice(1);    

var re = /file:\/\/\//gi;
if (abspath.match(re) != null) abspath = abspath.replace(re,""); // if this is indeed a local file, we strip the "file://" prefix from it.    

return(abspath);

}
hosturl=abspath()+"/";

相关文章

网友评论

      本文标题:获取当前页面的绝对路径

      本文链接:https://www.haomeiwen.com/subject/zldmvttx.html