Link to home
Start Free TrialLog in
Avatar of donb1
donb1

asked on

Include Script in html

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?
Avatar of seanpowell
seanpowell
Flag of Canada image

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.
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!
(the above steps will allow you to use SSI includes in .htm and .html files)
Avatar of ric7ho
ric7ho

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
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 https://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>
>> 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.
Avatar of donb1

ASKER

Would php be easier?
If so, how would I do it?
ASKER CERTIFIED SOLUTION
Avatar of intrwrks
intrwrks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial