0
<script type="text/javascript">
<!--
function FP_popUpMsg(msg) {//v1.0
 alert(msg);
}
// -->
</script>
</head>

<body style="background-color: #800080" onload="FP_popUpMsg('test message')">

This popup window appears on load of the webpage. I want to format this so that the user cannot access the page unless they click the OK button in the popup. Presently they can click the X in the browser (top right) and still get in

zt1983811
  • 1,011
  • 3
  • 14
  • 34
spin58
  • 7
  • 1
  • 2

1 Answers1

0

You could always use confirm, which returns true if the 'ok' button was clicked and false if the close or cancel buttons were clicked. MDN has a page on it: https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm. The question at How to stop page load in html static page has some solutions for stopping a page from loading, though they seem hackish and bound to fail at some point. Another solution to that part of the problem would be to redirect to a dedicated page; see How to redirect to another webpage in JavaScript/jQuery? for more.

A sample solution (pure JS, no libraries used here)

<html>
<head>
<script type = "text/javascript">
    function redirIfNotConfirmed(msg) {
      var confirmed = confirm(msg);
      if (!confirmed) window.location.href = "http://my.website.com/dummy_redir_page";
    }

    redirIfNotConfirmed("click ok to proceed");
</script>
</head>
JeremiahB
  • 896
  • 8
  • 15