-3

My network security professor want's us to create a web page that a user can't navigate away from using the URL bar, or bookmarks.

His hints were to use onbeforeunload and onunload.

Target browser is Firefox.

everett1992
  • 2,351
  • 3
  • 27
  • 38

3 Answers3

1
<html>
  <head>
    <script type="text/javascript">
      window.onbeforeunload = function() {
        setTimeout(function() {document.location.reload()}, 0);
      } 
    </script>   
  </head>
  <body>
    <a href="http://www.google.com">I won't work</a>
  </body>
</html>

If you try to navigate to another site using the address bar, bookmarks, or links, you will be brought back to this page.

everett1992
  • 2,351
  • 3
  • 27
  • 38
  • Wow, I totally shouldn't have tested that. I couldn't even close the tab in Chrome. It sure gets the job done. – ampersand Nov 19 '12 at 18:12
  • @ampersand you cant close the tab? In chrome on linux the only think I am prevented from doing is navigating to another page online. – everett1992 Nov 20 '12 at 20:23
  • It was surprising, but it froze the tab. I needed to force quit Chrome. I'm running Chrome 23.0.1271.64 Mac OS X 10.6.6. – ampersand Nov 21 '12 at 04:17
0
<html>

<head>
<title>Jquery stop</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">

   function unloadPage(){
       return "dont leave me this way";
   }

   window.onbeforeunload = unloadPage;

</script>
</head>

<body>

<a href="www.example.com/">I am leaving</a>
</body>
</html>

You could use JQUery to do all the work

h0lyalg0rithm
  • 150
  • 1
  • 6
0

so here is a example here, but for a full example

    <html>
      <head>
          <script type="text/javascript">
           window.onbeforeunload = function() {
              return "Are you sure you want to navigate away?";
           } 
          </script>   

      </head>
      <body>
        <a href="http://www.example.com">Link</a>

      </body>
</html>

Remember we are here to help and answer the question not to do you assignment

Community
  • 1
  • 1
ryanc1256
  • 570
  • 6
  • 23
  • If it's possible to give hint without doing the assignment I would love that. If I understand the assignment correctly he does not want a confirmation box to come up when you try to navigate away. This seems like something browser designers would try to prevent from happening, and all of my searches returned suggestions like yours. – everett1992 Nov 10 '12 at 06:00
  • @everett1992 im pretty sure it's imposible, well as far as my knowledge and searches and tries have gone. So you may have to have a play or just tell him its I don't know how to do it?? And If it was possible it is a very big security down fall as a website could keep the browser from closing and fundamentally stop the computer from shutting down as it would have to wait for the browser to close down but it cant as the browser cant close down due to the window cant navigate away – ryanc1256 Nov 10 '12 at 07:23
  • Those were my thoughts exactly, but I wanted to ask others for help or a hint before asking the professor. – everett1992 Nov 10 '12 at 17:07
  • @everett1992 The only way would be to delay but you only can delay it for like 1 second but then it the browser will move on and navigate away. – ryanc1256 Nov 10 '12 at 23:06
  • We found a way, I've added my own answer. – everett1992 Nov 12 '12 at 00:09