How to get the base path in jQuery?

∥☆過路亽.° 提交于 2019-12-02 21:47:42

You can get the protocol and the host separately, and then join them to get what you need

window.location.protocol + "//" + window.location.host + "/"

As a sidenote, window.location.pathname would contain the path.

You can use this statement

var baseUrl = document.location.origin;

Try this:

location.protocol + "//" + location.host

I think it will ok for you

var base_url = window.location.origin;

var host = window.location.host;

var pathArray = window.location.pathname.split( '/' );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!