使用jquery获取基本URL

Pri*_*nce 0 javascript jquery

我有一个网址http://xyz.in/pqr/v/index.php,我想只获得http://xyz.in/pqr/v/所以如何从url中删除index.php.

CJ *_*mki 6

试试这个.

  var host = window.location.protocol+'//'+window.location.host+'/'
  alert(host);
Run Code Online (Sandbox Code Playgroud)

如果你想最后避免'/',你可以使用它

var host2 = window.location.protocol+'//'+window.location.host
Run Code Online (Sandbox Code Playgroud)

看看这个有趣的演示