Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get query string parameters by JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:58:30 09月15日 Update

This article mainly introduces JavaScript how to obtain query string parameters, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Get query string parameters

Get the parameter value in url or append the query string, before that, we usually get the query string value through regular expressions, but now there is a new api, details can be seen here, we can deal with url in a very simple way.

For example, now that we have a url, "? post=1234&action=edit", we can use the following techniques to deal with this url.

/ / Assuming "? post=1234&action=edit" var urlParams = new URLSearchParams_ (window.location.search); console.log (urlParams.has ('post')); / / trueconsole.log (urlParams.get (' action')); / / "edit" console.log (urlParams.getAll ('action')); / / ["edit"] console.log (urlParams.toString ()); / / "? post=1234&action=edit" console.log (urlParams.append (' active','1')) / / "? post=1234&action=edit&active=1" Thank you for reading this article carefully. I hope the article "how to get query string parameters for JavaScript" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Characters strings queries parameters articles processing value interests at the same time skills ways more friends rules knowledge ribbons industry expressions details information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB Shulou Tech Info Docker Apple