“Obtenha parâmetros de URL JavaScript” Respostas de código

Obtenha o parâmetro do JavaScript de URL real

// https://testsite.com/users?page=10&pagesize=25&order=asc
const urlParams = new URLSearchParams(window.location.search);
const pageSize = urlParams.get('pageSize');
vmxes

JavaScript Get URL

var currentUrl = window.location.href;
Grepper

JS Verifique o parâmetro URL

const params = new URLSearchParams(window.location.search);

// Check if we have the param
if (params.has("myParam")) {
  console.log("Yep!  We have it.  Value is: " + params.get("myParam"));
} else {
  console.log("The param myParam is not present.");
}
Nuclear Man

JS obtenha o parâmetro URL

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const code = urlParams.get('code')
Awful Anaconda

JS Get URL Params

const params = new URLSearchParams(window.location.search);
const something = decodeURIComponent(params.get('hi'));
// or shorter, no need to use variables
decodeURIComponent((new URLSearchParams(window.location.search)).get('hi'))
Code Cat

Obtenha parâmetros de URL JavaScript

var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
 Run code snippet
Exuberant Echidna

Respostas semelhantes a “Obtenha parâmetros de URL JavaScript”

Perguntas semelhantes a “Obtenha parâmetros de URL JavaScript”

Mais respostas relacionadas para “Obtenha parâmetros de URL JavaScript” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código