Search code examples
javascripthtmlalertify

Need help redirecting to index.html after password entered


<script>
function password(){
    alertify.prompt("INGRESE LA CLASE", function (e, str) {
        if (str=='123'){ 
            // here! how to get into the another page, like "index.html"
        } else {
            alertify.log('ERROR! INGRESE LA CLAVE');
        } 
    }); 
}
</script>

<a href="index.html" onClick="password(); return false;">AQUI</a>

It works Alertify, but after OK, need some code to open the page index.


Solution

  • If what you want is that the function redirects the current page to the page in the href attribute of the clicked link, then

    <script>
    function password(event){
        alertify.prompt("INGRESE LA CLASE", function (e, str) {
            if (str=='123'){ 
                // here! how to get into the another page, like "index.html"
                window.location.href = event.target.href;
            } else {
                alertify.log('ERROR! INGRESE LA CLAVE');
            } 
        }); 
    }
    </script>
    <a href="index.html" onClick="password(event); return false;">AQUI</a>
    

    This will redirect to any page you have on href, either index.html or anything else. I wouldn't recommend this approach, though...