Solved

Include Script in html

Posted on 2003-11-12
8
1,540 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send Mail Via SMTP Replacement/Rework 11 60
Synchronizing CSS load 3 29
How can I   ajax html table  rows? 20 63
html input type 3 22
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now