CodeIgniter Forums
Call function when exiting browser? - 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: Call function when exiting browser? (/showthread.php?tid=38445)



Call function when exiting browser? - El Forum - 02-08-2011

[eluser]CappY[/eluser]
Is there way user to call function when exiting browser?

More special -> i want all to clear all DB Caches when user close website or exit browser.

And is there way to cache just one or few query ?

$this->db->cache_on();
-- query --
$this->db->cache_off();

?


Call function when exiting browser? - El Forum - 02-08-2011

[eluser]Mareshal[/eluser]
do it using javascript,an send a request to a specific page


Call function when exiting browser? - El Forum - 02-09-2011

[eluser]BrianJM[/eluser]
[quote author="Mareshal" date="1297202692"]do it using javascript,an send a request to a specific page[/quote]

I don't believe this is possible with JavaScript.


Call function when exiting browser? - El Forum - 02-09-2011

[eluser]Eric Barnes[/eluser]
It is possible but not sure if it is reliable across all browsers:
http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm

Basically use that to then call an ajax method to do your cleaning.


Call function when exiting browser? - El Forum - 02-09-2011

[eluser]BrianJM[/eluser]
[quote author="Eric Barnes" date="1297304074"]It is possible but not sure if it is reliable across all browsers:
http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm

Basically use that to then call an ajax method to do your cleaning.[/quote]

That method does not distinguish between closing the page and refreshing it. Just something to consider.


Call function when exiting browser? - El Forum - 02-09-2011

[eluser]InsiteFX[/eluser]
Maybe add a Destructor to your class.

See PHP Net

InsiteFX


Call function when exiting browser? - El Forum - 02-09-2011

[eluser]Jaketoolson[/eluser]
I agree with InsideFX - add a destructor to your class.

As a side note, there are ways using Javascript to process data when leaving the page (either going to new page, refreshing, or closing browser). I coded this for a data sensitive project where we had to be certain the user was aware they were leaving/closing the page.