Results 1 to 5 of 5

Thread: Preview HTML Window

  1. #1
    Join Date
    Nov 2005
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Preview HTML Window

    Here is my issue. I have designed a form that enables me to add updates to my site more efficiently. For the sake of efficiency, I recently concluded that if I could view the results of the form (in it's HTML output), prior to saving it and uploading it to my server, then I could change any mistakes.

    So, I went in search of a 'Preview HTML Window' snippet, if you will.

    One that I obtained and which really looked promising is this:

    <div><textarea></textarea></div>
    <div><button onclick="win = window.open ('', 'child', 'height=400,width=300'); win.document.write (document.getElementsByTagName ('TEXTAREA')[0].value); win.document.close(); win.focus()">Write</button></div>

    The only problem with the above is that it returns a preview window with ONLY the following words in the window:

    NaN minutes and NaN seconds

    However, if you look at the source code of the child window, the HTML is there!!!

    Can anyone offer any ideas or hopefully, a solution?

    Thank you!!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,165
    Thanks
    44
    Thanked 3,239 Times in 3,200 Posts
    Blog Entries
    12

    Default

    What did you put in the text area to get that? I tried it here and it worked fine in both IE6 and FF1.0.7.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2005
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi John....

    I posted some really simple HTML to test it and got that error I showed you. Let me ask this, you say you tried it 'here'. Did you post it on a web server and try it or on your local machine?

    I'm doing everything locally which is the way I do my work. It's not a 'gotta be on a server' type of script is it?

    Thanks!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,165
    Thanks
    44
    Thanked 3,239 Times in 3,200 Posts
    Blog Entries
    12

    Default

    By here, I mean on my trusty laptop running Windows XP Home with live update and IE6 and FF1.0.7. Like I said. I put your code on a page and ran it in both browsers. It did fine with simple things like:

    K

    and

    <span>Hi!</span>

    I even pasted in the code of the page itself, hit 'write' and then I had two of them. The second version wouldn't run until I changed child to child2 in the textarea, for obvious reasons (it was overwriting itself). Once I fixed that, the spawned copy worked just like the original. Here is the exact code I used (it is really just exactly what you posted, pasted into my standard HTML 'blank'):

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <div><textarea></textarea></div>
    <div><button onclick="win = window.open ('', 'child', 'height=400,width=300'); win.document.write (document.getElementsByTagName ('TEXTAREA')[0].value); win.document.close(); win.focus()">Write</button></div>
    
    </body>
    </html>
    I'm really at a loss as to what could be the problem on your end. Try my (really it is your) code and see if that makes any difference. Perhaps security or other settings on your browser are the problem or, if you have a different OS or browser than the ones I used.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2005
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Red face

    John...

    Thanks a bunch! Part of the problem (as I feel certain you suspected) was on my 'operator' (me) end. You were right. The code works. What I didn't think about (duh!) was the fact that my 'table generator' also used a snippet of javascript (to make a mouseover effect on some nav buttons). When I woke up to that fact, and tried the code without that script, it works as intended!

    The aforementioned mouseover script had the sole purpose of making my clients go 'oooh' & 'aaah' (they're easy to please, what can I say) but I can learn to live without them.

    Many thanks!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •