js中获取引用js的路径我在页面中使用了一个js文件如,http://localhost/WEB/SCRIPTS/aaa.js"
现在我要在aaa.js文件中获取这个引用的路径,怎样返回呢?
我要得到http://localhost/WEB 这个地址javascript

解决方案 »

  1.   

       var scripts = document.getElementsByTagName('script')//获所有script标签
        , script = scripts[scripts.length - 1]//获取当前加载到的script标签
    //如果是ID,src=document.getElementById('script的Id').src
        , src = script.src//获取当前加载到的script标签的src属性
    alert(src)
      

  2.   

    <%
        String path = request.getContextPath();
        String basePath = "";    if (path != "")
            basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
        else
            basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        request.setAttribute("cxp", basePath);
    %>
      

  3.   


    这个取到的不是我加载的这个js,当我使用多个时,得到的是最后一个js文件的路径
      

  4.   

    这个方法可行,请问下用javascript 怎么写呢,不要jQuery
      

  5.   

    看错,以为得到当前加载js的文件路径直接location.href就得到了是哪个页面加载的这个js了