Is there any method to get the URL without query s

2019-01-10 02:36发布

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

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

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

11条回答
Juvenile、少年°
2楼-- · 2019-01-10 03:04

Try this: window.location.href.split('?')[0]

查看更多
冷血范
3楼-- · 2019-01-10 03:04
location.toString().replace(location.search, "")
查看更多
Juvenile、少年°
4楼-- · 2019-01-10 03:04

Use properties of window.location

var loc = window.location;
var withoutQuery = loc.hostname + loc.pathname;
var includingProtocol = loc.protocol + "//" + loc.hostname + loc.pathname;

You can see more properties at https://developer.mozilla.org/en/DOM/window.location

查看更多
女痞
5楼-- · 2019-01-10 03:09
var url = window.location.origin + window.location.pathname;
查看更多
Animai°情兽
6楼-- · 2019-01-10 03:11

If you also want to remove hash, try this one: window.location.href.split(/[?#]/)[0]

查看更多
登录 后发表回答