Skip to content

JavaScript confirm title

  • by

This is not possible to change confirm box the title in JavaScript, from a security and anti-phishing point. The only way you could simulate it is by creating a modeless dialog window.

JavaScript confirm title

Simple example code to the default title of confirm(). There are many third-party JavaScript plugins that you could use to fake this effect so you do not have to write all that code.

<!DOCTYPE html>
<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" />
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
</head> 
<body>

 <script>
  ConfirmDialog('Are you sure');

  function ConfirmDialog(message) {
    $('<div></div>').appendTo('body')
    .html('<div><h6>' + message + '?</h6></div>')
    .dialog({
      modal: true,
      title: 'Delete message Confirm',
      zIndex: 10000,
      autoOpen: true,
      width: 'auto',
      resizable: false,
      buttons: {
        Yes: function() {
          // $(obj).removeAttr('onclick');                                
          // $(obj).parents('.Parent').remove();

          $('body').append('<h3>Confirm Dialog Result: <i>Yes</i></h3>');

          $(this).dialog("close");
        },
        No: function() {
          $('body').append('<h3>Confirm Dialog Result: <i>No</i></h3>');

          $(this).dialog("close");
        }
      },
      close: function(event, ui) {
        $(this).remove();
      }
    });
  };
</script>

</body>
</html>

Output:

JavaScript confirm title

Do comment if you have any doubts or suggestions on this Js confirm box topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.