javascript get querystring [duplicate]

你。 提交于 2019-12-09 14:32:47

问题


Possible Duplicate:
obtaining querystring from current url in javascript?

I was to get everything after the question mark in the url. Ive seen a way to do it that does not require a function but cannot find it for the life of me.

url

fsdhfbsdfj/index.html?hello

get

hello

回答1:


Use

var query = window.location.search;

If you want to get rid of the starting "?", use

var query = window.location.search.slice(1);

The properties of the location object are described here.




回答2:


var querystring=window.location.search.substring(1);



回答3:


Your title says "get querystring", but your question says "get everything after the question mark" which is something different and can include both a querystring and a hash.

I assume that when you say "the" url you are talking about the current Web page.

To get the querystring:

window.location.search

To get everything after the first ?:

window.location.href.split("?").slice(1).join("?");



回答4:


You can find the query string in window.location.search



来源:https://stackoverflow.com/questions/14463771/javascript-get-querystring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!