0

How to change the default JavaScript alerts from the browser to make it better? I've read how to change the style of alert box , but it's based on the click of a button .. I mean the alert which is the default browser without having to click the button. here's an example:

<?php
    include 'libraries/config.php';     

$id      = $_GET['id'];
$cart_id = $_GET['cart_id'];

    $myqry=mysqli_query($conn,"DELETE FROM cart_order_detail WHERE id='$id'");

    if ($myqry)
    {
        echo "<script language='javascript'>alert('Are you sure want delete this item ?');document.location='order.php';</script>";
    }
?>

enter image description here

can possible ?

Mohammad hayajneh
  • 623
  • 2
  • 11
  • 32
illogic
  • 225
  • 3
  • 18

3 Answers3

3

There is no way to style alert box modal. Because it is operating system native element and does not appear to be a part of DOM in any way.

You will need to create your own modal to be able to style it.

Please note: alert() stops execution of js on your page, and usually this is not desirable.

Nikola Mitic
  • 1,298
  • 3
  • 11
  • 23
1

You can't.

Web browsers do not provide a way for a website to override the look and feel of their native dialog boxes.

The only way to do it is to fake it by creating elements in the DOM which look like dialogs (the approach you dismissed in the question).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

No it is not possible. alert cannot be styled by CSS or configured. If you want to display something custom you should create your own or use a third party library like sweet alert or jQuery UI or anything.

Take care that these tools doesn't block the execution of the rest of the JavaScript code like alert

Ahmad Alfy
  • 13,107
  • 6
  • 65
  • 99