javascript - Browsers back button click with confirm box -
need create javascript confirm pop on click of browsers button. if click on button pop come , "you want go ahead ?" if click on yes have redirected previous page.
i have following code not working per requirement.
if(window.history && history.pushstate){ // check history api support window.addeventlistener('load', function(){ // create history states history.pushstate(-1, null); // state history.pushstate(0, null); // main state history.pushstate(1, null); // forward state history.go(-1); // start in main state this.addeventlistener('popstate', function(event, state){ // check history state , fire custom events if(state = event.state){ event = document.createevent('event'); event.initevent(state > 0 ? 'next' : 'previous', true, true); this.dispatchevent(event); var r = confirm("would save draft?"); if(r==true) { // nothing } else { self.location = document.referrer; } // reset state history.go(-state); } }, false); }, false); }
any in appreciable.
Comments
Post a Comment