So I ended up discovering the presence of this event "onbeforeunload" for html pages. Though this seems to have some issues with the Opera browser, It seems to work fine with IE, Firefox and Chrome. Haven't tested on safari. The code that helps me do it is quite fascinating as well.
A function named confirmExit() exists that just works like the confirm prompt, which provides with default options asking your opinion on leaving or staying on the same page. The code is as follows
window.onbeforeunload = confirmExit;
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
Following is a screen shot of how these pages look on various browsers