views:

37

answers:

2

I'd like to throw together a quick HTML preview window that takes the contents of a text area and shows it in a modal dialogue with a single close button. The contents should be rendered as HTML.

Not sure how to go about this.. what's the best way?

A: 

You can go for any of these modal boxes:

http://kirank.blog.com/2009/10/31/jquery-model-box/

ColorBox is another getting very popular.

Sarfraz
+2  A: 

If you're using jQuery UI, something like this:

HTML

<textarea id="mytext"></textarea>
<div id="dialog"></div>

JavaScript

$('#dialog').dialog({ modal: true, autoOpen: false });

function preview() {
  $('#dialog').html($('#mytext').val());
  $('#dialog').dialog('open');
}
casablanca
where does the button go that opens it? I'm a lot weak on JQuery...
Caveatrob
Anywhere you want. Just add a link or button somewhere and call `preview` when it's clicked, for example: `<button onclick="preview();">Preview</button>`
casablanca