Cancel window.location.href = ‘some url’;
Did some googling on this and didn’t really find any great solutions for canceling setting the window’s location. Say for example you have a grid whose datasource is filtered by parameters in the querystring and someone clicks “Show All” or forgets to filter the results; this may take a very long time to load and the user probably doesn’t want to wait and wants to cancel.
After playing with a couple different ideas the best I found to accomplish this was to set the locations href to itself on your cancel buttons click event, see below. I put it in a setTimeout because it will get hung up on the current thread that is trying to load the slow page.
onclick=”window.setTimeout(function() { window.location.href=window.location.href; }, 10);”
By reseting the window location’s href you cancel the event and reload to your current page. I’ve tested on Chrome, FF and IE, all seem to handle it quite well.
If anyone has a better way of doing this, i’m all ears!