Intercept browser function based exit
I want to produce a warning you are about to leave popup if the user tried to leave via browser based functions (back, forward, url bar, close tab, close browser ect)
but not if they use a page based function ( <a href>, form submit, javascript functions ect )
I have been trying to use code such as
- $(window).on( 'beforeunload' , function( event ) {
-
- if ( someCondition ) {
- return 'please dont leave';
- }
-
- });
In place of someCondition i have tried various pieces of code to attempt to establish if this or event contain a DOM object and only run the code if there it NOT a dom object present.
but so far i have had no luck
is is possible to do what i am attempting to do