PDA

View Full Version : Preview HTML Window



syn0psis
11-27-2005, 07:17 PM
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!!! :confused:

Can anyone offer any ideas or hopefully, a solution?

Thank you!!

jscheuer1
11-27-2005, 10:11 PM
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.

syn0psis
11-28-2005, 02:20 AM
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? :confused:

Thanks!

jscheuer1
11-28-2005, 04:19 AM
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'):


<!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.

syn0psis
11-28-2005, 12:51 PM
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!! :)