[Solved-5 Solutions] Query string values in javaScript - javascript Tutorial
Problem:
How to get a query string in javascript ?
Solution 1:
Using URLSearchParams is simple.
This code don't need jQuery. So we can use JavaScript:
Use this code:
Note: If a parameter is present several times (?foo=lorem &foo=ipsum), to get the first value as (lorem).
This function is case-sensitive.
Solution 2:
Repeating the regular expression search every time the script wants to access a parameter is completely. One single function to split up the parameters into an associative-array style object. Not working with the HTML 5 History API, this is only necessary once per page load.
i=main&mode=front&sid=de8d49b78a85a322c4155015fdce22c4&enc=+Hello%20&empty
Result:
To handle style-array query strings.
Solution 3:
You can use this:
Solution 4:
- To retrieve all parts of URL, including anchor, host, etc.
- It can be used with or without jQuery.
The jQuery plugin is different on elements.
Solution 5:
jQuery plugin:
The syntax is: