Skip to content
Advertisement

Javascript onbeforeunload to open window.open() popup

I am trying to write a onbeforeunload event that triggers a window.open(url) etc. I want it to be triggered if the user trys to leave the page or if they close their browser, but not when they click any of the buttons on the page. The buttons on the page post data to the same page via a javascript.

javascript:

JavaScript

The buttons calls a javascript function that creates a form and submits it. In that javascript function I set the global variable of doSync = false. I’ll include the basic code of this function just to illustrate it.

JavaScript

right now I am getting a Not Implemented error on the window.onbeforeunload = doSync; statement.

Any help would be appreciated.

Thanks,

Jim

Is there something wrong with my window.open? if i do a window.open('','','height=100,width=100');

it opens fine but this below does not.

JavaScript

Advertisement

Answer

doSync is a function, not a boolean; just create a variable and set it appropriately:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement