473,691 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript document.write question

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
Jul 20 '05 #1
2 2381
Brett Baisley wrote:
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.


What do you mean 'doesn't handle multiple lines very well'? 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/...haracters.html

This code generates a new window with a table.

<html>
<title>CodeAve. com(JavaScript New Window within Previous Page)</title>
<body bgcolor="#FFFFF F">
<script language="JavaS cript">
<!--
function open_new_window () {
new_window =
open("","displa yWindow","width =575,height=620 ,left=10,top=10 \n");

// open new document
new_window.docu ment.open();

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

new_window.docu ment.write("<ht ml>\n");
new_window.docu ment.write("<he ad>\n");
new_window.docu ment.write("<me ta http-equiv='Content-Type'
content='text/html; charset=windows-1252'>\n");
new_window.docu ment.write("<ti tle>Table of Data</title>\n");
new_window.docu ment.write("<st yle type='text/css'>\n");
new_window.docu ment.write(" td { text-align: right; }\n");
new_window.docu ment.write(" td.1 { text-align: left; }\n");
new_window.docu ment.write("</style>\n");
new_window.docu ment.write("</head>\n");
new_window.docu ment.write("<bo dy>\n");
new_window.docu ment.write("<ta ble border='1' cellspacing='1' width='555'
height='546' style='border-collapse: collapse'>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td class = '1' width='111'>Son nenstand
in Grad über dem Horizont ein<br>Elevatio n of the sun (degrees above the
horizon</td>\n");
new_window.docu ment.write(" <td class = '1' width='111'>Opt imaler
Anstellwinkel des Spiegels °A<br>Optimal mirror orientation °A</td>\n");
new_window.docu ment.write(" <td class = '1'
width='111'>Ene rgieerzeugung Watts<br>Power output Watts</td>\n");
new_window.docu ment.write(" <td class = '1' width='111'>Mit der
erzeugten Energie können Sie Grams<br>With the above displayed energy
you can heat Grams</td>\n");
new_window.docu ment.write(" <td class = '1' width='111'>con verted to
lbs:</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>0°</td>\n");
new_window.docu ment.write(" <td>60°</td>\n");
new_window.docu ment.write(" <td>138,56 W</td>\n");
new_window.docu ment.write(" <td>552 g</td>\n");
new_window.docu ment.write(" <td>1 lb 3.5 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>5°</td>\n");
new_window.docu ment.write(" <td>63°</td>\n");
new_window.docu ment.write(" <td>150,12 W</td>\n");
new_window.docu ment.write(" <td>598 g</td>\n");
new_window.docu ment.write(" <td>1 lb 5.1 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>10°</td>\n");
new_window.docu ment.write(" <td>67°</td>\n");
new_window.docu ment.write(" <td>161,46 W</td>\n");
new_window.docu ment.write(" <td>643 g</td>\n");
new_window.docu ment.write(" <td>1 lb 6.7 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>15°</td>\n");
new_window.docu ment.write(" <td>70°</td>\n");
new_window.docu ment.write(" <td>172,48 W</td>\n");
new_window.docu ment.write(" <td>687 g</td>\n");
new_window.docu ment.write(" <td>1 lb 8.2 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>20°</td>\n");
new_window.docu ment.write(" <td>73°</td>\n");
new_window.docu ment.write(" <td>183,06 W</td>\n");
new_window.docu ment.write(" <td>729 g</td>\n");
new_window.docu ment.write(" <td>1 lb 9.7 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>25°</td>\n");
new_window.docu ment.write(" <td>77°</td>\n");
new_window.docu ment.write(" <td>193,13 W</td>\n");
new_window.docu ment.write(" <td>769 g</td>\n");
new_window.docu ment.write(" <td>1 lb 11.1 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>30°</td>\n");
new_window.docu ment.write(" <td>80°</td>\n");
new_window.docu ment.write(" <td>202,57 W</td>\n");
new_window.docu ment.write(" <td>807 g</td>\n");
new_window.docu ment.write(" <td>1 lb 12.5 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>35°</td>\n");
new_window.docu ment.write(" <td>83°</td>\n");
new_window.docu ment.write(" <td>211,30 W</td>\n");
new_window.docu ment.write(" <td>842 g</td>\n");
new_window.docu ment.write(" <td>1 lb 13.7 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>40°</td>\n");
new_window.docu ment.write(" <td>87°</td>\n");
new_window.docu ment.write(" <td>219,23 W</td>\n");
new_window.docu ment.write(" <td>873 g</td>\n");
new_window.docu ment.write(" <td>1 lb 14.8 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>45°</td>\n");
new_window.docu ment.write(" <td>90°</td>\n");
new_window.docu ment.write(" <td>226,27 W</td>\n");
new_window.docu ment.write(" <td>901 g</td>\n");
new_window.docu ment.write(" <td>1 lb 15.8 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>50°</td>\n");
new_window.docu ment.write(" <td>93°</td>\n");
new_window.docu ment.write(" <td>232,37 W</td>\n");
new_window.docu ment.write(" <td>926 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 0.7 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>55°</td>\n");
new_window.docu ment.write(" <td>97°</td>\n");
new_window.docu ment.write(" <td>237,43 W</td>\n");
new_window.docu ment.write(" <td>946 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 1.4 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>60°</td>\n");
new_window.docu ment.write(" <td>100°</td>\n");
new_window.docu ment.write(" <td>241,41 W</td>\n");
new_window.docu ment.write(" <td>962 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 1.9 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>65°</td>\n");
new_window.docu ment.write(" <td>103°</td>\n");
new_window.docu ment.write(" <td>244,25 W</td>\n");
new_window.docu ment.write(" <td>973 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 2.3 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>70°</td>\n");
new_window.docu ment.write(" <td>107°</td>\n");
new_window.docu ment.write(" <td>245,90 W</td>\n");
new_window.docu ment.write(" <td>980 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 2.6 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>75°</td>\n");
new_window.docu ment.write(" <td>110°</td>\n");
new_window.docu ment.write(" <td>256,32 W</td>\n");
new_window.docu ment.write(" <td>981 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 2.6 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>80°</td>\n");
new_window.docu ment.write(" <td>113°</td>\n");
new_window.docu ment.write(" <td>245,49 W</td>\n");
new_window.docu ment.write(" <td>978 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 2.5 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>85°</td>\n");
new_window.docu ment.write(" <td>117°</td>\n");
new_window.docu ment.write(" <td>243,39 W</td>\n");
new_window.docu ment.write(" <td>970 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 2.2 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write(" <tr>\n");
new_window.docu ment.write(" <td>90°</td>\n");
new_window.docu ment.write(" <td>120°</td>\n");
new_window.docu ment.write(" <td>240,00 W</td>\n");
new_window.docu ment.write(" <td>956 g</td>\n");
new_window.docu ment.write(" <td>2 lbs 1.7 ozs</td>\n");
new_window.docu ment.write(" </tr>\n");
new_window.docu ment.write("</table>\n");
new_window.docu ment.write("</body>\n");
new_window.docu ment.write("</html>\n");

// close the document
new_window.docu ment.close();
}
// -->
</script><a onclick="open_n ew_window()"
style="cursor:p ointer;cursor:h and;" ><font color="#008080" ><u>Open New
Window</u></font></a>

</body>
</html>

Jul 20 '05 #2
mscir wrote:
[...] 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/...haracters.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="#FFFFF F">
Text color?
<script language="JavaS cript">
"type" attribute?
<!--
function open_new_window () {
new_window =
open("","displa yWindow","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.docu ment.open();

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

new_window.docu ment.write("<ht ml>\n");
See above.
new_window.docu ment.write("<he ad>\n");
new_window.docu ment.write("<me ta 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.docu ment.write("<ti tle>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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4259
by: annoyingmouse2002 | last post by:
Hi there, sorry if this a long post but I'm really just starting out. I've been using MSXML to parse an OWL but would like to use a different solution. Basically it reads the OWL (Based on XML) and puts values in a number of arrays and then puts the contents of the array in a HTML table. I'd like to keep the array structure. I've checked out all sorts of different javascript parsers but have not met with a great deal of success with any...
5
2201
by: Lucian Sandor | last post by:
Hello everyone, While I'm a newbie here, I a not new to google, so please don't send me back, it would be useless. First of all I have to specify I am working on a Blogger.com template, therefore anything I'll write should be stuck on a single file. I thought about creating a funny pop-up. <a href="javascript:myFunction();"... that's because, as you will see, the code for the popup is pretty complex. I've insterted myFunction somewhere...
14
5466
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
136
9355
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
6
5580
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
8
5209
by: Mateusz Viste | last post by:
Hi, I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)... I recently put the following script online: <script type="text/javascript"><!-- function playmedia(mediafile) { newwindow=window.open(); if (window.focus) {newwindow.focus()} newwindow.document.write('<html>');
2
3453
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in advance for responding. I have made a stub of the codes for better understanding. Situation: I have a Java servlet (HelloWorldServlet) running on a Tomcat (5.5.26) server on a Linux machine (compiled in JDK1.4.2). It writes Javascript to construct...
0
8600
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9079
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8952
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8796
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6457
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5817
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4553
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1954
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.