/

HTML / CSS / JavaScript Tutorial

HTML Event attribute: onpagehide

[this page | pdf | back links]

The HTML onpagehide attribute specifies the event that is triggered when the user navigates away from a page. It applies to <body> elements.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body onpagehide="return myOnpagehide()">
Try navigating away from page, e.g. by following this link:
<a href="http://www.nematrian.com">nematrian homepage</a><br>

<script>
function myOnpagehide() {alert("Page being hidden");}
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile