0

Estoy haciendo un pa pagina web con diferentes documentos html. Desde windows me funciona, pero con OS X no.

Este es el método en el que lo tengo escrito:

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'
    }


}

Codigo dentro del 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>
2
  • Para redireccionar a otra página debes incluir la parte window.location.href = 'http://tudomioOlocalhost.com/MainPage.html'
    – Thakur
    el 8 dic. 2017 a las 18:49
  • No no tiene porque. Si la ruta de la nueva página es la misma que la actual no debería hacer falta indicar la url completa. el 8 dic. 2017 a las 18:51

1 respuesta 1

1

Deberías utilizar window.location.href="<url>";

De esta forma te funcionará en todos los navegadores.

Si la nueva página está en la misma ruta que la actual debería bastarte con indicar la página a cargar:

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

Si no te funciona en algún navegador puedes probar introduciendo la url completa (pero no debería hacer falta):

var path = window.location.origin + (window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1));
window.location.href = path + 'MainPage.html';
4
  • Lo he intentado así también y me da el mismo resultado. Estoy intentando redireccionar a otra pagina html de la misma carpeta. el 8 dic. 2017 a las 18:44
  • Con window.location.replace no te va a funcionar en muchos navegadores. Con window.location.href debería funcionarte en todos. ¿Te da algún error? el 8 dic. 2017 a las 18:49
  • No debería hacer falta, pero puedes probar a poner la url completa. He editado la respuesta para mostrarte cómo hacerlo. el 8 dic. 2017 a las 19:07
  • Ya he visto el problema, a ver si sabes que puedo hacer. Resulta que si pongo esto " window.location.href = '../MainPage.html' " y me funciona si en el form que tengo no subo una imagen. He actualizado la pregunta con el resto el div que contiene la imagen. el 8 dic. 2017 a las 20:30

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.