0

This might be a stupid question. But I have the following javascript:

var popit = true;
window.onbeforeunload = function() { 
    if(popit == true) {
        popit = false;
        return 'Bah bah bah\nWhah whah whah'; 
    }
}

But it show when moving on to next page in the flow. It should only show when browser is being closed. Does anyone know how to do this?

pbaris
  • 4,525
  • 5
  • 37
  • 61

1 Answers1

0

You can't. With javascript you can listen if the page is ready to unload (change page, close tab, close browser), but you can't make distinct between them. Event unload and beforeunload are triggered when the page is unloaded, not differences between if its a tab closing or navigator closing.

Marcos Pérez Gude
  • 21,869
  • 4
  • 38
  • 69