I am approaching for the first time in JavaScript and I am trying to implement the onload function to show a message every time the page of my site is loaded. Can you help me by showing me some lines of code?
I am approaching for the first time in JavaScript and I am trying to implement the onload function to show a message every time the page of my site is loaded. Can you help me by showing me some lines of code?
Never use body onload. It is very simple for other scripts to overwrite.
Instead use addEventListener which will ADD your function to the load and cannot be overwritten
<html>
<header>
<meta charset="UTF-8">
</header>
<script>
window.addEventListener("load", function() {
alert("Hey!");
})
</script>
<body>
</body>
</html>
That said, it is very weird that an alert was dismissed since it is system modal. Are you sure you use alert?