Solved

Include Script in html

Posted on 2003-11-12
8
1,534 Views
Last Modified: 2013-11-18
In Active Server pages, I can prepare an include file that contains a Header, navbar etc that I want to include in every page on the site.  A simple one line of script includes the file.   If I want to make a change, only one file needs to be changed.   Can something like this be done using only html?  If so, how?
0
Comment
Question by:donb1
8 Comments
 
LVL 31

Expert Comment

by:seanpowell
ID: 9731687
You don't need asp to include files using the SSI directive (Server Side includes), but the pages will need the extension of .shtml

Here's an overview:
http://bignosebird.com/ssi.shtml

Note - You can also do this using the Include Page component of FrontPage - which do not require the FP extensions to function.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9732333
In the IIS management console, right click on the Default Website (or on the website in question) and click on Properties.  

Under the Home Directory tab, click on the Configuration button.  

Under the Mappings tab is a list of file extensions.  Edit the one for .shtm or .shtml and take note of all the settings (path,verbs,etc), but don't change any values here.  

Click the Add button and create similar entries for .htm and .html

Restart IIS.  viola!
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9732495
(the above steps will allow you to use SSI includes in .htm and .html files)
0
 
LVL 1

Expert Comment

by:ric7ho
ID: 9733017
The problem with shtml is that u need special server configuration, which is often complicated.

It is IMPOSSIBLE to include a file using ONLY HTML, simply because html is a "client-side language".

But u might do this: (although it is not a very convenient method, i must admit):
In everypage:
<script src="afile.js"></script>

In afile.js:
document.write("HTML that you want to include");
  *beware that do not use ' " ' (double quotation mark) between the brackets in afile.js.

hope this might help
ric7ho
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 33

Expert Comment

by:knightEknight
ID: 9733294
it is possible to include other files with just client code, but this includes javascript and not just HTML.  Also, it is less reliable ... SSI is much better.  But if you are really looking for a client-only solution, give this a shot:



<HTML>

<HEAD>
<SCRIPT language='JavaScript'>

 function include(url)  // must be a fully qualified URL, I don't know why
 {
   if ( document.all )
   {
     var xml = new ActiveXObject("Microsoft.XMLHTTP");
     xml.Open( "GET", url, false );
     xml.Send()
     document.writeln(xml.responseText);
   }
   else  // Netscape code from http://www.experts-exchange.com/javascript/Q.20290896.html
   {
     if ((location.host=='' && url.indexOf(location.protocol)==-1) || url.indexOf(location.host)==-1)
     {
       netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");
     }

     var dest = new java.net.URL(url);
     var dis  = new java.io.DataInputStream(dest.openStream());
     var res  = "";
     while ((line = dis.readLine()) != null)
     {
       res += line + java.lang.System.getProperty("line.separator");
     }
     dis.close();
     document.writeln(res);
     return res;
   }
 }

</script>
</head>

<BODY>
<BR><B>See the included file below:</B><BR>

&nbsp;<p>
<div id="test">
<SCRIPT language='JavaScript'>
   // must be a fully qualified URL -- can be any type of file (html,jsp,asp,etc)
   include("http://www.foxnews.com/");
</SCRIPT>
</div>


</body>
</html>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9734099
>> it is possible to include other files with just client code, but this includes javascript and not just HTML.

what I meant was "this uses javascript as well as HTML".  Poor use of the word "include" in this context.
0
 

Author Comment

by:donb1
ID: 9736331
Would php be easier?
If so, how would I do it?
0
 
LVL 4

Accepted Solution

by:
intrwrks earned 100 total points
ID: 9740775
I think it would be easier to do this in php, but it all depends on if you are familar with php and if your hosting server supports php.

Here is what it would look like in php:

     <?php
     include "common.inc";
     ?>

     <!-- the rest of your document -->
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now