Avatar of paddycobbett

asked on 

jQuery: preventing a user to navigate from the current page upon a condition

Please take a look at the code attached, i'm trying to require a confirmation from the user that they want to change the page by applying an onclick on all anchors. Don't worry, it's not one of those nuissance prompts! .. the intention is that it only appears if the user has any unsaved changes. It's probably quite obvious what i'm trying to do from the code. An immediate (without a prompt) return of false from an onclick action causes the anchor to not experience a click (right??), but when i put it in this prompt it seems to navigate anyway.. the prompt appears momentarily whilst the pages begins to relocate. Can anyone shed some light on what i'm missing here to get it working?
	   if (modified){
		jConfirm("<font size='3'>You have unsaved content changes. Are you sure you want to navigate to a different page?</font>", "Prompt", function(r) {
			if (r){
				return true;
				return false;

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon