您的位置:首页 > Web前端 > JavaScript

js中获得项目名称

2015-10-10 14:04 381 查看
function getRootPath(){

    //获取当前网址,如: http://localhost:8088/test/test.jsp
    var curPath=window.document.location.href;

    //获取主机地址之后的目录,如: test/test.jsp

    var pathName=window.document.location.pathname;

    var pos=curPath.indexOf(pathName);

    //获取主机地址,如: http://localhost:8088
    var localhostPaht=curPath.substring(0,pos);

    //获取带"/"的项目名,如:/test

    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);

    return(localhostPaht+projectName);

    } 

    

    source=getRootPath()+"/resources/img/temp/404.png";

    document.getElementById("a").innerHTML="<img src="+source+" width='1570' height='780'>";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: