Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show HTML in alert window same like iframe?

i want to show HTML in alert window same like iframe..? can i do this...

<script>
alert("<html><body><h1>this is alert heading</h1></html></body>")
</script>

how can i do this..?

like image 874
CSS Guy Avatar asked May 21 '12 17:05

CSS Guy


3 Answers

If your asking how to display the HTML markup per se in the alert box, escape it:

alert("\<html\>\<body\>\<h1\>this is alert heading\</h1\>\</html\>\</body\>")

If you are asking how to format the alert box using HTML you cannot. You need to create a modal dialog box as one of the other answers indicates.

like image 33
marteljn Avatar answered Oct 20 '22 01:10

marteljn


You can't do it via alert().

You can mimic it using a modal dialog. There are lots of modal dialog libraries - jQuery UI has a pretty powerful one.

like image 43
ceejayoz Avatar answered Oct 20 '22 00:10

ceejayoz


Instead of using alert, I would use a Pop Up. And I recommend you to use something like jQuery Dialog , look at http://jqueryui.com/demos/dialog/

Sample :

First, create a div to wrap your html elements,

<div id='my-dialog-id' title='my dialog title'>
  <h1>this is alert heading</h1>
</div>

Then include some javascript with jQuery and jQueryUI

  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $(function() {
    $("#my-dialog-id").dialog(); //Here I select a div with id my-dialog-id and start the plugin.
  } );
  </script>

And it's ready!

like image 142
Guilherme de Jesus Santos Avatar answered Oct 20 '22 01:10

Guilherme de Jesus Santos