I have very simple code just to show a warning before page refreshed. The code uses Codeigniter as a framework (not sure if Codeigniter is related to the issue). I have a view file (test_v.php) with the following code:
<?php ?><!DOCTYPE html><html><head><meta charset="utf-8"><title></title></head><body ><p>Test onbeforeunload</p><script type="text/javascript"> window.onbeforeunload = function () { return 'Do you really want to perform the action?'; }</script></body></html>
Then I load this view file in a controller test.php$this->load->view('test_v');
When I refresh the page, I expect to see a warning dialogue with the text 'Do you really want to perform the action?', but no warnings are shown at all. I have tested with IE, Firefox, Chrome. None works.I have also tried adding the js code to the body label like this:
<body onbeforeunload=" return 'Do you really want to perform the action?'">
not working either.Could anyone help? Thanks a lot!