The window.location.href
property returns the URL of the current page, for example, if I open put in the console the command below on the page of this question, we will return the URL of this page:
Script:
console.log(window.location.href);
Return:
/questions/129417/windows-location-n%c3%a3o-funciona
Notice that the return had with http://
thus to assign a new value to the window.location.href
, we should also put the protocol http
, as this references a new URL, if it does not place it will understand that it is an internal page of your site.
According to your code, without the http
in the front would return something like this:
https://www.seusite.com/www.google.pt
Making the change your script looks like this:
function eliminaParagem (){
var confirma =confirm("Tem a certeza que quer eliminar a paragem");
if (confirma==true){
window.location.href="http://www.google.pt";
}
}
This way redirecting to another site.
You want it to go to an internal or external page?
– Pedro Luzio
You want me to go to an external or internal page?
– Pedro Luzio
Just try using
window.location
, with thehttp
(if it is external page).– HDeiro
This type of behavior is peculiar when, for example, the button that triggers the redirect routine is inside a <form> with Submit, or even in the lines below the </form>. One solution is to put the button (or link) above the <form tag>
– Bertonni Magnus