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 :)