How To Preview HTML Code (in a textarea)?

Discussion in 'JavaScript' started by lokielookies, Aug 15, 2008.

  1. #1
    On my page, I have a text area which contains HTML code.

    How can I add a 'Preview' button (preview must open in a new window)?

    ;)
     
    lokielookies, Aug 15, 2008 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Instead try using a online WYSIWYG editor such as TinyMCE. [http://tinymce.moxiecode.com/]
    Else you will have to POST the contents of the textarea to a script!
    
    <!-- XHTML code -->
    <form name="myform" id="myform" action="preview.php" method="post">
    <textarea rows="25" cols="80" name="htmlarea" id="htmlarea"></textarea>
    <input type="submit" value="Submit" />
    </form>
    
    HTML:
    
    <?php
    //code for preview.php
    echo $_POST['htmlarea'];//you may need to use stripslashes() depending upon magic quotes configuration!
    ?>
    
    Code (PHP):
    Also, not all user agents may render it properly due to quirks mode.
    Your best option, I think, would be to use TinyMCE!
     
    rohan_shenoy, Aug 15, 2008 IP
  3. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #3
    i'm agree if u using tinyMCE :D
     
    ghprod, Aug 22, 2008 IP