How to get the base path in jQuery?

前端 未结 4 1836
囚心锁ツ
囚心锁ツ 2021-02-03 19:26

window.locationworks fine, but returns me the whole, absolute path, like http://domain.xyz/punch/lines. But I only need http://domain.xyz/

4条回答
  •  死守一世寂寞
    2021-02-03 19:59

    I think it will ok for you

    var base_url = window.location.origin;
    
    var host = window.location.host;
    
    var pathArray = window.location.pathname.split( '/' );
    

提交回复
热议问题