javascript - 使用 jquery 获取基本 url

标签 javascript jquery

我有一个网址http://xyz.in/pqr/v/index.php我只想得到 http://xyz.in/pqr/v/那么如何从 url 中删除 index.php。

最佳答案

试试这个。

  var host = window.location.protocol+'//'+window.location.host+'/'
  alert(host);

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

var host2 = window.location.protocol+'//'+window.location.host

查看此FIDDLE DEMO

关于javascript - 使用 jquery 获取基本 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20878368/

相关文章:

javascript - 通过单击链接通过 JavaScript 打开 Bootstrap 4 Modal

javascript - 无法使用 jsColor 获取 jQuery 中按钮的颜色

jQuery : cursor automatically placed at the end with val()

jquery - 使用 MVC Ajax 更新局部 View 内的局部 View

javascript - 使用 google api 登录我的网站

javascript - 带有providedIn : 'root' is an empty object的 Angular 服务

javascript - React 组件 View 没有得到更新

jquery - 如何将 ZeroClipboard 剪辑粘到新插入的元素上?

javascript - 我怎样才能得到&前面的url

javascript - Core2 中缺少 DotNet 新的 Knockout