zoukankan      html  css  js  c++  java
  • js中获取项目路径的小插件

    //立即执行的js
    (function() {
        //获取contextPath
        var contextPath = getContextPath();
        //获取basePath
        var basePath = getBasePath();
        //将获取到contextPath和basePath分别赋值给window对象的g_contextPath属性和g_basePath属性
        window.g_contextPath = contextPath;
        window.g_basePath = basePath;
    })();
    
    /**
     * @author 孤傲苍狼
     * 获得项目根路径,等价于jsp页面中
     *  <%
            String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
        %>
     * 使用方法:getBasePath();
     * @returns 项目的根路径
     *  
     */
    function getBasePath() {
        var curWwwPath = window.document.location.href;
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        var localhostPath = curWwwPath.substring(0, pos);
        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
        return (localhostPath + projectName);
    }
    
    /**
     * @author 孤傲苍狼
     * 获取Web应用的contextPath,等价于jsp页面中
     *  <%
            String path = request.getContextPath();
        %>
     * 使用方法:getContextPath();
     * @returns /项目名称(/EasyUIStudy_20141104)
     */
    function getContextPath() {
        return window.document.location.pathname.substring(0, window.document.location.pathname.indexOf('/', 1));
    };

    我从别人那里偷过来的:

    https://home.cnblogs.com/u/xdp-gacl/

  • 相关阅读:
    laravel的workflow流程插件
    [php]laravel框架容器管理的一些要点
    laravel 自带消息notification通知
    laravel5.5的定时任务详解(demo)
    Laravel核心代码学习
    laravel 加载指定版本的mongodb
    Linux安装Composer
    composer全量镜像使用方法
    laravel在github地址
    node anyproxy ssi简易支持
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/6090370.html
Copyright © 2011-2022 走看看