How to obtain the current page url and query parameters
Obtain the current page url and query parameters in JavaScript.
Sometimes out of need, we need to obtain the URL parameters of the current page on the client, you may know that if it is obtained on the server side, such as PHP or JSP, it is relatively easy, in fact, JavaScript is simpler.
Let's take a look at the following URL:
Http://www.webfans.org/index.php? Query.
The previous part is the current URL of the page, that is, http://www.webfans.org/. what is the subsequent part? Query.
You only need to use the following code to obtain the URL of the current page:
<Script language = 'javascript '>
VaR currenturl = This. Location. href
</SCRIPT>
Of course, you can also change the URL of a page through the above method to achieve page orientation.
Obtain the query parameter? The following code is used in the query section.
<Script language = 'javascript '>
VaR currentquery = This. Location. Search.
</SCRIPT>