Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirm Dialog when i close the browser?

Tags:

javascript

i need to display confirm dialog box before close browser window using javascript or PHP. the confirm box should come when i click the close button of browser. other wise don't display dialog. please help me any.

like image 998
chittibabu Avatar asked Dec 13 '10 10:12

chittibabu


1 Answers

You should handle the onbeforeunload event...

function closeEditorWarning(){
    return 'Are you sure?'
}
window.onbeforeunload = closeEditorWarning;

Or use jquery, window.attachEvent / window.addEventListener to do it nicely

like image 62
ivy Avatar answered Nov 12 '22 04:11

ivy