Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda