current position:Home>[front end learning notes] save the front-end related codes

[front end learning notes] save the front-end related codes

2022-04-29 07:53:26Micro love

  • Get the of the deployment project root Address
// Get the project url route 

function getRootPath() {
    
    // 1、 Get the current full path , Such as : http://localhost:8080/springmvc/page/frame/test.html
    let curWwwPath = window.location.href;
    //  Get the current relative path : /springmvc/page/frame/test.html
    let pathName = window.location.pathname;
    //  Get the host address , Such as : http://localhost:8080
    let local = curWwwPath.substring(0, curWwwPath.indexOf(pathName));
    //  Get the belt "/" The project name , Such as :/springmvc
    let projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    //http://localhost:xxxx/ Project name 
    return local + projectName;
}

// webapp The path of  http://localhost:xxxx/ Project name /
// window.location.href = getRootPath() + "/pages/index.html";

copyright notice
author[Micro love],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290548191314.html

Random recommended