detecting exit-intent caused by back/forward, close tab/browser and url bar

detecting exit-intent caused by back/forward, close tab/browser and url bar

i know that the beforeUnload event can be used to detect when the user is moving off the page.

I also know that events which nothing to do with the DOM such as back/forward, close tab/browser and url bar use cannot be detected directly which means the following psudocode is not possible

  1. $(window).on('beforeUnload' , function ( e ) {

  2.       if( event.target = back/forward || close tab/browser || url bar ) {
  3.             
  4.             return "please dont leave";

  5.       }     

  6. });

Is there any way to achieve the desired result by process of illimination
If detect if the event was NOT on a DOM object?