add a timer before it pops up when the page is loaded
Mark E.
Yes, you can add a timer before the popup is displayed when the page loads by using the setTimeout()
function.
Here's an example:
<!DOCTYPE html>
<html>
<head>
<title>Hello Popup</title>
</head>
<body onload="showDelayedPopup()">
<script>
function showDelayedPopup() {
setTimeout(function() {
alert("hello");
}, 5000); // wait 5 seconds before showing popup
}
</script>
</body>
</html>
In this code, we have added an onload
event to the body
element, which will call the showDelayedPopup()
function when the page has finished loading. The showDelayedPopup()
function uses the setTimeout()
function to wait for 5 seconds (5000 milliseconds) before displaying the popup using the alert()
method. You can adjust the time by changing the value of the second parameter of setTimeout()
.