Javascript document.write question

B

Brett Baisley

Hello

I have a block of html code that I want to run by calling a javascript
function to print it. Its basically a table with menu items in it that is
the same for many pages, and instead of copying/pasting everytime I change
it, I figure this will be better, as I only change it once.

The problem is, document.write doesn't handle multiple lines very well, so I
was wondering what is the best way to do this? Maybe there is even a better
way then javascript calls.

Anything will be great! Thanks!

Brett
 
T

Thomas 'PointedEars' Lahn

mscir said:
[...] If you mean the data is not easy to read on the generated page,
insert \n where you want a newline to begin. Post your code for more
specific suggestions.

http://www.devguru.com/Technologies/ecmascript/quickref/escaped_characters.html

This code generates a new window with a table.

<html>

DOCTYPE declaration?
<title>CodeAve.com(JavaScript New Window within Previous Page)</title>
<body bgcolor="#FFFFFF">

Text color?
<script language="JavaScript">

"type" attribute?
<!--
function open_new_window() {
new_window =
open("","displayWindow","width=575,height=620,left=10,top=10\n");

Wrong. The options (third) argument of window.open() must not
contain newline. And _window._open() is recommended since there
is document.open(). The function should be defined within
the "head" element, not the "body" element, to be available always.
// open new document
new_window.document.open();

// Text of the new document goes here
// Replace your " with ' or \" or document.write statements will fail

new_window.document.write("<html>\n");

See above.
new_window.document.write("<head>\n");
new_window.document.write("<meta http-equiv='Content-Type'
content='text/html; charset=windows-1252'>\n");
^^^^^^^^^^^^
What about UAs that does not support this Windows character set?
ISO-8859-1 is better.
new_window.document.write("<title>Table of Data</title>\n");
^^
Not only that this is and creates invalid HTML for the most part, a
smaller example would have sufficed. You have posted more than 200
lines of garbage!


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top