From out of curiosity can i Control window.onbeforeunload event like check if the user decided to leave the page or stay in it and can I raise an alert or some function based on
You can ONLY return a string which will show a dialog confirmation displaying the string you returned (But with additional ok/cancel buttons to confirm the action).