So window.location
refers to the location of your current window, so changing it of course takes you away from the window you're on. To open a new window, you want window.open
- see Open a URL in a new tab (and not a new window) using JavaScript
However, I'd suggest instead, using a link that you intercept the default behavior for if the user answers false, and otherwise fallback to the default behavior.
ie:
<a href="/some/url" id="foo">bar</a>
$('#foo').click(function(e){
var answer=confirm("Do u want to continue?") {
if (answer==false) {
document.form.field1.focus();
e.preventDefault();
}
}
});
Although I'd have to double check if that actually works, I haven't worked with confirm much at all, so you might have to call the e.preventDefault() outside of that block.