Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html in javascript confirm box?

Is it possible to insert HTML code in a JavaScript confirm box?

I just tried & it does not seem to work (I try to add a HTML link), see my code below

<html> 
  <head> 
     <script type="text/javascript"> function show_alert() { confirm(<a href="www.url.com">Link text</a>); } </script> 
  </head>
  <body>
    <input type="button" onclick="show_alert()" value="Show alert box" />
  </body>
</html>

I suspect I might have to use a library such as "jquery-ui's dialog" to get this working

like image 801
Adrien Be Avatar asked Mar 12 '12 16:03

Adrien Be


People also ask

How do you confirm a box in JavaScript?

The confirm() method displays a dialog box with a message, an OK button, and a Cancel button. The confirm() method returns true if the user clicked "OK", otherwise false .

What does confirm box return in JavaScript?

A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.

How do you use confirm in JavaScript?

Javascript | Window confirm() Method The confirm() method is used to display a modal dialog with an optional message and two buttons, OK and Cancel. It returns true if the user clicks “OK”, and false otherwise. It prevents the user from accessing other parts of the page until the box is closed.

What is the difference between an alert box and a confirmation box in JavaScript?

Alert box is used if we want the information comes through to the user. Confirm box is used if we want the user to verify or accept something. 2. You need to click “OK” to proceed when an alert box pops up.


2 Answers

You can only insert plaintext to alert(), confirm() and prompt() boxes.

like image 106
mx0 Avatar answered Sep 20 '22 14:09

mx0


No, it isn't possible with the alert function.

However, if you want confirm boxes with html code, you could add a <div> with an absolute position on the screen, which can contain any html you want.

like image 42
heinrich5991 Avatar answered Sep 19 '22 14:09

heinrich5991