有没有什么方法可以在没有查询字符串的情况下获取 URL? [英] Is there any method to get the URL without query string?

查看:22
本文介绍了有没有什么方法可以在没有查询字符串的情况下获取 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似 http://localhost/dms/mduserSecurity/UIL/index.php?menu=true&submenu=true&pcode=1235 的 URL.

I have a URL like http://localhost/dms/mduserSecurity/UIL/index.php?menu=true&submenu=true&pcode=1235.

我想获取不带查询字符串的 URL:http://localhost/dms/mduserSecurity/UIL/index.php.

I want to get the URL without the query string: http://localhost/dms/mduserSecurity/UIL/index.php.

在 JavaScript 中有什么方法可以做到这一点吗?目前我正在使用 document.location.href,但它返回完整的 URL.

Is there any method for this in JavaScript? Currently I am using document.location.href, but it returns the complete URL.

推荐答案

试试这个:

let path = window.location.href.split('?')[0]
console.log({path})

这篇关于有没有什么方法可以在没有查询字符串的情况下获取 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆