7

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?

Caveatrob
  • 12,667
  • 32
  • 107
  • 187
  • Which part is tripping you up? – Matchu Jul 16 '10 at 18:08
  • @Matchu: I assume no part yet... He is *probably* looking for pre-made model box solutions. – Sarfraz Jul 16 '10 at 18:10
  • You can go for any of these modal boxes: http://kirank.blog.com/2009/10/31/jquery-model-box/ [ColorBox](http://colorpowered.com/colorbox/) is another getting very popular. – Sarfraz Jul 16 '10 at 18:08

1 Answers1

5

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
  • 69,683
  • 7
  • 133
  • 150
  • Anywhere you want. Just add a link or button somewhere and call `preview` when it's clicked, for example: `` – casablanca Jul 16 '10 at 19:12