Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 11 - February 13, 2002

A JavaScript Version of /COPY

Hey, Ted:

I enjoyed your JavaScript tip so much that I thought I'd send you one of mine.

I've often thought HTML would benefit from something like the /COPY directive that we RPGers enjoy so much. This would be especially useful for building a list of links that you want to appear on multiple pages (without the need to resort to Frames).

It is possible to emulate a copy include using JavaScript stored in an external file. Here's a simple example.

Create a text file, such as menu.js, to contain the code to be copied:

document.write("<TABLE BGCOLOR=BEIGE><TR><TD>" +
"<A HREF=" + "Page1.htm" + ">Page 1</A>" +
"</TD></TR><TR><TD>" +
"<A HREF=" + "Page2.htm" + ">Page 2</A>" +
"</TD></TR><TR><TD>" +
"<A HREF=" + "Page3.htm" + ">Page 3</A>" +
"</TD></TR></TABLE>")

Reference the text in the <SCRIPT> tag in other HTML files:

<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript" SRC="menu.js">
</SCRIPT>
</BODY>
</HTML>

-- Phil Hope

Thanks, Phil. It hadn't occurred to me to use the document object's write method.

By the way, you probably know it, but another way to code those anchor tags is to use the back slash (\) as an escape character for quotation marks, like this:








document.write("<a href=\"http://www.itjungle.com\">Goto MS --</a>")
document.write("<a href=\"http://www.google.com\">Goto google</a>")

You might also like to investigate Sever-side Includes (SSI), Phil. They let you include files in the same way, but the copied files can contain any HTML source, not just JavaScript.

-- Ted

Sponsored By
WORKSRIGHT SOFTWARE INC.

Do you need to verify that Cappahayden Newfoundland Canada has a postal code of A0A 1S0?

Do you need to retrieve the city name and province name associated with Canadian postal code A0A 1X0?

WorksRight Software, Inc. can help. Our CPC System contains all 766,000+ Canadian postal codes along with the matching city and province name. We also provide the area code, lat/lon, and time zone. Our yearly subscription provides six updates per year and unlimited telephone support. Visit our Web site at www.worksright.com to learn more about CPC and order a 30-day, no hassle, free trial. Or call 601-856-8337.  We'll be glad to answer all your questions.

THIS ISSUE
SPONSORED BY:
WorksRight Software, Inc.
Business Computer Design Int'l.
BACK ISSUES
TABLE OF CONTENTS
A JavaScript Version
of /COPY
SQL and Multi-member
Files
Reader Feedback and Insights: Keeping Users Informed
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 2/13/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.