Redirecting On Confirm True
I want to make it so the user clicks a link, they get a confirm box. If they click OK, they get sent to a new php function. I've tried: function confirmReset() { var r = confirm(
Solution 1:
There is no string
method. It gives an error. Also consider adding return false
to your function in order to prevent the default link action.
HTML:
<ahref="#"onclick="return confirmReset();">Test</a>
JavaScript:
functionconfirmReset() {
var r = confirm('Are you sure?');
var url = window.location.pathname;
var pathArray = url.split('/'); // <-- no need in "string()"var host = pathArray[1];
var newHost = '/headquarters/designReset';
if (r == true) {
window.location = host + newHost;
//document.location.href = '/headquarters/designReset';
} else {
alert('it didnt work');
}
returnfalse; // <-- add this line
}
Post a Comment for "Redirecting On Confirm True"