Use the onpageshow attribute to execute a script when a user navigates to a page.
Example
You can try to run the following code to implement onpageshow attribute −
<!DOCTYPE html>
<html>
<body onpageshow = "display()">
<h2>Tutorialspoint</h2>
<p>Simply Easy Learning</p>
<script>
function display() {
alert(You're back!");
}
</script>
</body>
</html>