Use custom alert in javascript

1

I'm trying to use something other than the default javascript alert and apparently switching syntax does not work. For example, this code works.

$mysqlInsert = mysqli_query($conexao,$sqlInsert);
            if (!mysqlInsert) {
                die('Error: ' . mysqli_error()); 
            }
            else {
                echo '<script>window.alert("Produto adicionado com sucesso!");
                        window.location.href="main.php";</script>';
                }
}

But that is not (the library is being called correctly):

$mysqlInsert = mysqli_query($conexao,$sqlInsert);
            if (!mysqlInsert) {
                die('Error: ' . mysqli_error()); 
            }
            else {
                echo '<script>swal("Produto adicionado com sucesso!");
                        window.location.href="main.php";</script>';
                }
}

I noticed that only when I use onclick, on a button for example, that I can call the custom alert. Can anyone explain me why?

    
asked by anonymous 04.10.2015 / 22:23

0 answers