www.webdeveloper.com
Results 1 to 7 of 7

Thread: window.onbeforeunload problem

  1. #1
    Join Date
    Apr 2010
    Posts
    4

    window.onbeforeunload problem

    I'm making a annoying page I will show to my class as a bad example and a site you should get out of as fast as possible/stay away from but I can't get it to work properly.

    I'm trying to make the page redirect you when you answer yes or no in a confirmation box but it just keeps going to the page the user types in.

    is there any way I can force the browser to do as I want to instead of what the user wants?

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  3. #3
    Join Date
    Apr 2010
    Posts
    4
    I actually forgot to post it >.<

    Code:
    function confirmation() {
    	var answer = confirm("Vil du vekk?")
    	if (answer)
    	{
    		alert("Okay da snakkes vi!");
    		window.location = "http://www.google.no"
    	}
    	else{
    		alert("Kult at du blir");
    		window.location = "http://www.kvasir.no"
    }
    }
    window.onbeforeunload = confirmation;

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Eeer, no, I am afraid you can not force the user to go where you want him to, onbeforeunload. All you can do is to ask him if he is sure he wants to leave/change/close the page. You can not redirect him like that.

  5. #5
    Join Date
    Apr 2010
    Posts
    4
    So it's no way that I can make the buttons link to a page I want him to go to?

  6. #6
    Join Date
    Apr 2010
    Posts
    4
    Not even if I just use a alert box instead of confirmation box?


    sorry if this turned into a double post instead of just getting added to the first post.

  7. #7
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I don't think you can. You see, if the user wants to change the session, he is fully able to change the session (leave the page, close the TAB or even close the browser). You can not interfere with the user's will. That is absolutely normal.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles