?
Solved

Include Script in html

Posted on 2003-11-12
8
Medium Priority
?
1,581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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…

649 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