window.location.replace (); it does not work

0

I'm doing a web page with different html documents. Since windows works for me, but with OS X no.

This is the method in which I have it written:

function guardarCookies() {

    if ($("#Conditions").prop("checked") == false) {

        alert("You must accept the terms of service and conditions.");
    } 
    else if ($("#Password").val().localeCompare($("#Password_confirmation").val())) {

        alert("The password and the confirmation of the password aren't the same.");

    } 
    else if ($("#Gender option:selected").val().localeCompare("0") == 0) {

        alert("You must choose a gender.");

    } 

    else {

        document.cookie = name + ":Name=" + document.getElementById("Name").value + ";";
        document.cookie = name + ":LastName=" + document.getElementById("LastName").value + ";";
        document.cookie = name + ":Email=" + document.getElementById("Email").value + ";";
        document.cookie = name + ":Password=" + document.getElementById("Password").value + ";";
        document.cookie = name + ":Password_confirmation=" + document.getElementById("Password_confirmation").value + ";";
        document.cookie = name + ":dia=" + document.getElementById("dia").value + ";";
        document.cookie = name + ":mes=" + document.getElementById("mes").value + ";";
        document.cookie = name + ":ano=" + document.getElementById("ano").value + ";";
        document.cookie = name + ":Gender=" + $("#Gender option:selected").val() + ";";
        document.cookie = name + ":Ncard=" + document.getElementById("Ncard").value + ";";
        document.cookie = name + ":mesCD=" + document.getElementById("mesCD").value + ";";
        document.cookie = name + ":anoCD=" + document.getElementById("anoCD").value + ";";
        document.cookie = name + ":codigo=" + document.getElementById("codigo").value + ";";
        document.cookie = name + ":Publicidad=" + $("#Publicidad").prop("checked") + ";";
        document.cookie = name + ":Imagen=" + document.getElementById("Imagen_subida").src + ";";    

    window.location.href = '../MainPage.html'
    }


}

Code within the form

            <div id="Name_sname" class="Inputs col-md-12">

                <input class="input" type="text" id="Name" placeholder="First" required>
                <input class="input" type="text" id="LastName" placeholder="Last" required>


                <input id="bimg" onclick="clickButton()" type="image" src="Images/bimg.png" width="40" height="40">
                <input id="fotocargada" type="file" accept="image/*" onchange="loadPicture()" class="formulario">
                <img id="Imagen_subida" src="" style="width:40px;height:40px;">

            </div>
    
asked by Alfonso Rodríguez 08.12.2017 в 19:07
source

1 answer

1

You should use window.location.href="<url>";

This way it will work on all browsers.

If the new page is on the same route as the current one, it should be enough to indicate the page to load:

window.location.href = 'MainPage.html';

If it does not work in a browser you can try entering the full url (but it should not be necessary):

var path = window.location.origin + (window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1));
window.location.href = path + 'MainPage.html';
    
answered by 08.12.2017 в 19:16