Simpy have a JSP based website tht runs on tomcat on a machine, and is used to configure some files on that machine.
Configuration save is achieved by, clicking Save button, which kicks off a restart servlet that runs a few scripts, redirection also included with an href..
The offending code:
<a onclick="if(confirm('Sava changes?')){window.location='<%=request.getContextPath()%>/restart.do'}" href="<%=request.getRequestURL()%>#">
Save Changes
</a>
As stated in the title, works fine under linux environment but in windows environment, the page redirects fine but the restart servlet is never fired.
Any suggestions welcome guys
In your
onclickhandler, you’re not doing anything to prevent the default action of the link, which is to follow thehref. So although you’re settingwindow.location, that’s immediately being overridden by the browser following the link.In old DOM0 style handlers (the kind you’re using), you can prevent the default action of the link by adding a
return false;. So:…or preferably:
…or even better, look into hooking up your JavaScript handlers via DOM2-style event handling instead (
addEventListeneron standards-supported browsers,attachEventfor IE8 and earlier).