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..?
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With