3

Hello all am trying to redirect user to redirect to another page when user decides to reload if he is asked for confirmaton. The function are getting executed but the window.location.href seems not to be working.

window.onbeforeunload = function () {
        return "Are you sure?";
    }
    window.onunload = function () {
        submitexamonunload();
        console.log("Too bad. Goodbye.");
    }


function doneexam(){
    if($("#std_store_exam").data("type") == "demo"){
        console.log("Into done exam."+$("#std_store_exam").data("type")+"inner");
        window.location.href = "demoexam.php";
    }else{          
        storeres();
        window.location.href = "studentdashboard.php";
    }

Tried some options availabe and researched also. Any help is appreciated.

santoshu
  • 51
  • 6
  • 1
    No, as that function will be called when a user decide to leave your page all together as well, hence stopping them is not suppose to be allowed, so I suggest you do that in another way – Asons Dec 03 '16 at 13:31
  • 1
    You can't redirect if the user has already decided to leave (thankfully). You can only redirect if the user clicks "cancel" in the onbeforeunload prompt (http://stackoverflow.com/questions/16695886/using-onbeforeunload-event-url-change-on-selecting-stay-on-this-page). – JJJ Dec 03 '16 at 13:33
  • 1
    hi all i am trying to redirect to page if user reloads the page. He is not supposed to reload the page. @lgson please suggest some way. – santoshu Dec 03 '16 at 14:27
  • 1
    There is no way to detect whether it is a reload or a user leave the page. Follow the link @JJJ suggest in above comment and you'll find suggestions – Asons Dec 03 '16 at 14:35

0 Answers0