1

It's showing dialogue and after some second dialogue is hiding.it navigate to another page.

I want to stop navigation and when i complete my work in dialogue. press ok(button) then it continue to navigation.

I write jquery in page

$(window).bind('beforeunload',function(){    
    var continued=document.getElementById("Form:testID1").value;
    if(continued==="true"){
        PF('dialogwidgetvar').show();
    }
}); 

//I tried this one as Suggestion

  function f(){
             var continued=document.getElementById("Form:testID").value;
             if(continued==="true"){
                 PF('dialogWidgetVar').show();
             }
        }
 window.addEventListener('beforeunload', f(), true);
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
vishvas chauhan
  • 342
  • 1
  • 4
  • 8
  • 1
    What should happen if 'your work' isn't completed and user turn off his computer?! To answer question, there is no way to use any relevant method to handle all possible cases like still e.g an asteroid strike user's house – A. Wolff Oct 21 '15 at 07:43
  • And you technically can't 'block' the beforeunload. Search the internet. Reason: prevent pages/sites from capturing your browser and preventing you from navigating away. And this is totally not related to jsf/primefaces – Kukeltje Oct 21 '15 at 07:57
  • i know but i am asking any other way we can prevent navigation some time.@A.Wolff – vishvas chauhan Oct 21 '15 at 08:21
  • can we do when page is unload after that we show dialog? @Kukeltje – vishvas chauhan Oct 21 '15 at 08:30
  • You can't prevent navigation... And sure you can load a dialog on a new page... IF the user navigates to that new page... – Kukeltje Oct 21 '15 at 08:40

2 Answers2

0

You can't do any work at this moment in/from the onbeforeunload, that is by design in the html specs. Firefox won't even show your custom text anymore.

See also:

Community
  • 1
  • 1
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
-1

What you need to do is hook into the window.onbeforeunload and return a message from there. The string returned from that function (event handler) is displayed in a prompt (messagebox). Have a look at the following for further details of this event https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload

Here's a working sample http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onbeforeunload

<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">

<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>

<a href="http://www.w3schools.com">Click here to go to w3schools.com</a>

<script>
function myFunction() {
    return "Write something clever here...";
}
</script>

</body>
</html>
Don
  • 6,632
  • 3
  • 26
  • 34
  • can you post the sample code, so we can see. Try posting your javascript sample – Don Oct 21 '15 at 10:04
  • There are a dozen of posts on Stackoverflow that refer to this. So if that were the question, there are many 'duplicates'. But the OP wants to **not** leave the page then and do 'work' in the onbeforeunload. That cannot be done – Kukeltje Oct 21 '15 at 11:24