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

189
Visualizações
How to safely use "&" symbol in a javascript variable without it turning to "&"?

I am trying to execute the following code:

<button onclick="increment()">Increment</button>
<div id="iframe">
<script>
var id = 139000;
var link='<iframe src="https://somewebsite.com/something.aspx?sa=1&pid=' + id + '" height="600px" width="100%" />';
function increment(){
id++;
document.getElementById('iframe').innerHTML = id + link ;
}
</script>
</div>

But while executing, the & in src="" converts to &amp; which breaks the original URL and doesn't go to the desired destination. I looked up on the internet but as I am a noob, I was not able to figure it out. Please help me to make this work!

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

0

All you need to do is

<button onclick="increment()">Increment</button>
<div id="iframe">
<script>
var id = 139000;
var link='<iframe src="https://somewebsite.com/something.aspx?sa=1&pid=' + id + 
'" height="600px" width="100%" />';
var new_link = link.replaceAll('&amp;','&');

function increment(){
id++;
document.getElementById('iframe').innerHTML = id + new_link;
}
</script>
about 4 years ago · Juan Pablo Isaza Relatório

0

This is definitely a blogger issue, and the reason behind happening is :

The character "&" is an ISO HTML reserved character used to denote the start of a parameter.

To overcome this the Blogger editor translate the & you enter to the HTML entity, &amp; , that will display & when the page or URL is rendered in a browser, so that you don't have to do it yourself.

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