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

163
Visualizações
onload function(this) from onclick in another page

I have a page where there is a button. The button has an onclick function, where it calls the function pop to produce an alert. The alert shows the attribute of the button's data-message.

I am trying to redirect this function to onload to another page, hence the href.

What I would like to produce is for the alert to be displayed on the 2nd page as well when the body onloads.

I have tried to change and swap my codes between the 2 different HTML, however I often get the error of Uncaught TypeError: e.getAttribute is not a function.

Here are the relevant codes for page 1 where the button needs to be clicked:

<a href="dump2.html"><button type="button" data-message="button1" onclick="pop(this)">click</button></a>
<script>
function pop(e) {
    alert(e.getAttribute("data-message"));
}
</script>  

Page 2 where I will onload the attribute I have gotten from the button clicked on Page 1

<body onload="pop(this)"> </body>
<script>
  function pop(e) {
      alert(e.getAttribute("data-message"));
  }
</script>

Any help would be greatly appreciated. Thanks :)

about 4 years ago · Santiago Trujillo
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