Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
How to Get 10 from this link (https://google.com/?ib=10)

Check this image I have this link in (note this link not from search URL) var link = https://google.com/?ib=10 in main.js file. Now how to get that 10 from this link in javaScript on Page load

I have tried this way

var link1 = link;
const url3 = new URLSearchParams(link1);
    const ur = url3.get("ib");
    var finaltgid = ur;
    alert(ur);

But its not working may be this code only work when we use window.location.search Instead of var or const

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

urlsearchparams does not parse full url, you need to pass only query part, like this:

var link = 'https://google.com/?ib=10';
const url = new URLSearchParams(new URL(link).search);
const ib = url.get("ib");
console.log(ib);

about 4 years ago · Juan Pablo Isaza Relatório

0

URLSearchParams only accepts the actual query part in the constructor. You are including the full link.

about 4 years ago · Juan Pablo Isaza Relatório

0

Edit: For a given link you can just supply the link in place of document.location (which directly fetches the pages current location)

Considering this as Vanilla JS. You can do the following.

let params = (new URL(document.location)).searchParams;

let ib = parseInt(params.get('ib')); // is the number 10

Note, using the parseInt to get the value as a number.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda