使用javascript从URL获取路径和查询字符串 [英] Get path and query string from URL using javascript

查看:78
本文介绍了使用javascript从URL获取路径和查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

http://127.0.0.1:8000/found-locations/?state=--&km=km

我希望如此:

found-locations/?state=--&km=km

我如何在javascript中执行此操作?

how do i do this in javascript?

我试过 window.location.href 但它给了我整个网址

我试过 window.location.pathname.substr(1)但它给了我 found-locations /

I tried window.location.href but it is giving me whole url
I tried window.location.pathname.substr(1) but it is giving me found-locations/

推荐答案

使用 location.pathname location.search

(location.pathname+location.search).substr(1)

这篇关于使用javascript从URL获取路径和查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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