Skip to content

Instantly share code, notes, and snippets.

@viveksoundrapandi
Created September 20, 2012 09:17
Show Gist options
  • Save viveksoundrapandi/3754854 to your computer and use it in GitHub Desktop.
Save viveksoundrapandi/3754854 to your computer and use it in GitHub Desktop.
Trigger native window of browser
$(function(){
var submitted = false;
//links having the below class will not trigger native widow
$(".cancel_submit").live('click',function (e){
submitted=true;
});
window.onkeydown = function(e){
var key = e.keyCode ? e.keyCode : e.charCode ? e.charCode : false;
if (((e.ctrlKey || e.metaKey)&&key==82 )||key==116)
{
submitted=true;
}
}
window.onbeforeunload = function()
{
if(!submitted)
{
// the string below will be displyed only in certain browsers, and others will display its own text
str = "Closing your browser window will cancel your loan application\nA new application on another site may result in additional credit checks that can impact your ability to get a loan.";
return str;
}
submitted=false;
}
});
@viveksoundrapandi
Copy link
Author

NOTE: You cant write an event listener for the buttons in this window for security reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment