Using HTML include file with JavaScript

Posted on 2003-03-05
Medium Priority
Last Modified: 2013-11-18
I am trying to run a java menu. All the js files are in the menu directory at the root of Web site. I want to use this HTML page as an include file and a header from other directories, it only works when the file calling is in the same directory. Below is some of the code from the header.html file. How can I "call", from an ASP page, this js file from inside an include file from another directory?

Ex: (Header.Html)
<BODY bgcolor="#3A6EA5" text="#FFFFFF">

<SCRIPT LANGUAGE="JavaScript1.2"
<p align="center"><font size="4" face="Arial">Web Site header</font></p>
<p align="center"> </p>

EX: (Page.asp)
<!--#include file="menu/Header.html"-->
Question by:Kenyonjr
LVL 19

Accepted Solution

webwoman earned 300 total points
ID: 8074872
This is tough...

You can't use the path where the include file is, since it's not in the same directory as the ASP page, and that's where you need to calculate the path from.

Why not use an absolute address for the include? If it's the same include all the time, and it's not moving, that should work.

So rather than Menu_loader.js you'd use http://www.mysite.com/myfiles/Menu_loader.js

You're in the same domain, so you don't have any cross domain issues. It should work.
LVL 16

Expert Comment

ID: 10097643
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: webwoman {http:#8074872}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question