Home > coding, dojo > dojo.back – finally working

dojo.back – finally working

5. Mai 2009 moldi

It took me quite a while to get dojo.back working in that way, that i prevents that the user is leaving my site accidentaly.

As far as I understood the documentation, dojo.back.setInitialState should have been enough to catch the back button action. But I had to add another historyState to get the intended behaviour. Perhaps this might be useful to someone out there:

dojo.addOnLoad(function() {
	dojo.back.setInitialState({
		back : function() {
			if (confirm('Do you want to leave this site?')) {
				history.back();
			} else {
				history.forward();
			}
		},
		forward : function() { console.log("User clicked forward"); },
		changeUrl : true
	});

	dojo.back.addToHistory({
		back : function() {
			console.log("initCompleted-back was clicked!");
		},
		forward : function() {
			console.log("initCompleted-forward was clicked!");
		},
		changeUrl : 'state1'
	});
});
Kategoriencoding, dojo Tags:
Kommentare sind geschlossen
mmm