CodeIgniter Forums
Verify before page refresh or back - is there a way? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Verify before page refresh or back - is there a way? (/showthread.php?tid=55885)



Verify before page refresh or back - is there a way? - El Forum - 11-14-2012

[eluser]Barwick[/eluser]
Question - is there a way to verify (via pop-up or some other method) before a user's back to page refresh or hit the browser back button?

For example, if I'm on a page and I go to hit the 'back' button or do a browser page refresh, before I'm able too I'll need to verify (via a pop-up) that I actually want to leave the page...

Not idea where to start with this. Scripts/code/examples anyone? I realize this might not be a Codeigniter related question. Or maybe it is...

Cheers,
Mike


Verify before page refresh or back - is there a way? - El Forum - 11-14-2012

[eluser]Aken[/eluser]
You'd need to use Javascript. Curious why you want to do it, though? I would typically advise against using them, because they're annoying.


Verify before page refresh or back - is there a way? - El Forum - 11-14-2012

[eluser]Barwick[/eluser]
Typically, I would agree 100%. But this would only be used on a wizard-campaign builder type of thing - which the entire page is all Ajax. Just testing the application I've hit the back button myself a couple times by mistake lol. So an "Are you sure you want to exit?" message or pop-up is a good way to remind/prevent. My thoughts anyways...


Verify before page refresh or back - is there a way? - El Forum - 11-14-2012

[eluser]solid9[/eluser]
Yes JavaScript is the way to this.
You need to repost your question again on JavaSript forums.


Verify before page refresh or back - is there a way? - El Forum - 11-14-2012

[eluser]Mirge[/eluser]
Heh, no need to repost on a different forum -- it's very simple. You want to bind to the "onbeforeunload" event. Here's a SO question that's been answered that explains it in greater detail:

http://stackoverflow.com/questions/1299452/how-do-i-stop-a-page-from-unloading-navigating-away-in-js


Verify before page refresh or back - is there a way? - El Forum - 11-14-2012

[eluser]solid9[/eluser]
@mirge

yeah I forgot Google is our best friend. ^__^