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?
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!
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)
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 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.X MLHTTP");
xml.Open( "GET", url, false );
xml.Send()
document.writeln(xml.respo nseText);
}
else // Netscape code from https://www.experts-exchange.com/javascript/Q.20290896.html
{
if ((location.host=='' && url.indexOf(location.proto col)==-1) || url.indexOf(location.host) ==-1)
{
netscape.security.Privileg eManager.e nablePrivi lege("Univ ersalConne ct");
}
var dest = new java.net.URL(url);
var dis = new java.io.DataInputStream(de st.openStr eam());
var res = "";
while ((line = dis.readLine()) != null)
{
res += line + java.lang.System.getProper ty("line.s eparator") ;
}
dis.close();
document.writeln(res);
return res;
}
}
</script>
</head>
<BODY>
<BR><B>See the included file below:</B><BR>
<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>
<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.X
xml.Open( "GET", url, false );
xml.Send()
document.writeln(xml.respo
}
else // Netscape code from https://www.experts-exchange.com/javascript/Q.20290896.html
{
if ((location.host=='' && url.indexOf(location.proto
{
netscape.security.Privileg
}
var dest = new java.net.URL(url);
var dis = new java.io.DataInputStream(de
var res = "";
while ((line = dis.readLine()) != null)
{
res += line + java.lang.System.getProper
}
dis.close();
document.writeln(res);
return res;
}
}
</script>
</head>
<BODY>
<BR><B>See the included file below:</B><BR>
<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.
what I meant was "this uses javascript as well as HTML". Poor use of the word "include" in this context.
ASKER
Would php be easier?
If so, how would I do it?
If so, how would I do it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.