Is it possible to customize an alert?

1

Between an if and else I have a call from an alert to return a response to the user, since the alert layout itself is not very much in line with the site layout, I would like to know how I can customize it.

if(ainput5 == false || ainput4 == false || ainput3 == false || ainput2 == false || ainput == false){
    alert('Para finalizar a compra é necessario informar a quantidade de salgados.');
    document.formMonteCaixa.creditCard5.focus();
  }
    
asked by anonymous 11.06.2018 / 05:08

2 answers

1

Brief response: No

The browser alert is a simple DOM alert, as described in the W3C "show an alert to the user and wait for it to close"; as a rule: there is no specification, although browsers can even let you customize how they do with scrool bar: link but this would be out of specification

How to customize (Simple alternative)

You need to make your own alert and imitate browser behavior by javascript.

example:

JavaScript:

<script>
    function customAlert(message) {
        var div = document.createElement("div");
        div.classList.add("custom-alert");
        var close = document.createElement("a");
        close.textContent = "[x]";
        close.classList.add("close"); // para o seu css
        close.addEventListener("click", () => {
            document.body.removeChild(div);
        }, true);
        div.appendChild(close);
        div.appendChild(document.createTextNode(message));
        document.body.appendChild(div);
    }

    customAlert("ola");
</script>

CSS

.custom-alert {
    /* o css do seu alerta */
}

W3C dom alert: link

    
11.06.2018 / 13:45
0

I use sweetalert, very simple and easy to use. Take a look at here documentation.

    
11.06.2018 / 19:24