如何获取JavaScript中没有任何参数的URL? [英] How to get the URL without any parameters in JavaScript?

查看:110
本文介绍了如何获取JavaScript中没有任何参数的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用:

alert(window.location.href);

我得到包括查询字符串在内的所有内容。有没有办法,只是让主URL部分,例如:

I get everything including query strings. Is there a way to just get the main url part, for example:

http://mysite.com/somedir/somefile/

而不是

http://mysite.com/somedir/somefile/?foo=bar&loo=goo


推荐答案

这是可能的,但你必须从 location object

This is possible, but you'll have to build it manually from the location object:

location.protocol + '//' + location.host + location.pathname

这篇关于如何获取JavaScript中没有任何参数的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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