windows.location navigation error

If beforeupload function is attached to windows and any event/ function changes the windows.location and we choose “Stay on this page” it will through error.

We need to use try catch for the solution.

binding beforunload event for page
$(window).on(‘beforeunload’, function(e){ return “must”  });

following code is solution for if we called ajax call and using callback with change windows location

try{

if ($(“#Anchor”).length > 0) {
$(“#Anchor”).attr(“href”, url).get(0).click();
} else {
$(“<A>”).attr(“id”, “Anchor”).attr(“href”, url).appendTo(document.body).get(0).click();
}
} catch (e) { }

 

Leave a Reply