[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1584
  • Last Modified:

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?
0
donb1
Asked:
donb1
1 Solution
 
seanpowellCommented:
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
 
knightEknightCommented:
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
 
knightEknightCommented:
(the above steps will allow you to use SSI includes in .htm and .html files)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ric7hoCommented:
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
 
knightEknightCommented:
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
 
knightEknightCommented:
>> 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
 
donb1Author Commented:
Would php be easier?
If so, how would I do it?
0
 
intrwrksCommented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now