Call external file with <script src="content.js"></script> insteadof SSI.

B

Blue®

I would like to call the content of content.htm (containing only HTML
codes) into index.htm.

This is usually done by renaming index.htm to index.shtml and use this tag:

<!--#include file="content.htm" -->

But I do not want to use SSI. Is it possible to call it using something
like:

<script src="content.js"></script>

If yes, how should content.js look like?
 
M

Martin Honnen

Blue® said:
I would like to call the content of content.htm (containing only HTML
codes) into index.htm.

This is usually done by renaming index.htm to index.shtml and use this tag:

<!--#include file="content.htm" -->

But I do not want to use SSI. Is it possible to call it using something
like:

<script src="content.js"></script>

If yes, how should content.js look like?

The HTML element to include another document on the client is
<iframe src="content.html"
width="putsomewidthere"
height="putsomeheighthere"></iframe>
 
B

Blue®

Martin said:
The HTML element to include another document on the client is
<iframe src="content.html"
width="putsomewidthere"
height="putsomeheighthere"></iframe>

Negative. Using iframe will cause a box with a fixed width to be
created. I need the width of the cell adjusted automatically/accordingly
to the content of content.htm.
 
H

Hywel Jenkins

I would like to call the content of content.htm (containing only HTML
codes) into index.htm.

This is usually done by renaming index.htm to index.shtml and use this tag:

<!--#include file="content.htm" -->

But I do not want to use SSI. Is it possible to call it using something
like:

<script src="content.js"></script>

If yes, how should content.js look like?

Full of document.write() function calls I would guess.
 
M

McKirahan

Hywel Jenkins said:
Full of document.write() function calls I would guess.

--
Hywel

Kill the Crazy Frog
http://www.petitiononline.com/crzyfrg/

Or build an array and "document.write" the join; as in:

var i = 0;
var a = new Array();
a(i++) = "<table border='1'>";
a(i++) = "<tr>";
a(i++) = " <td>Hello World!</td>";
a(i++) = "</tr>";
a(i++) = "</table>";
document.write a.join("\n");
 
M

Martin Honnen

Blue® said:
Negative. Using iframe will cause a box with a fixed width to be
created. I need the width of the cell adjusted automatically/accordingly
to the content of content.htm.

Script can try to adjust the iframe:
<http://www.faqts.com/knowledge_base/view.phtml/aid/1076/fid/127>

If you really need to load some resource from your server then there are
also some browser dependent ways, IE/Win has the download behaviour
<http://www.faqts.com/knowledge_base/view.phtml/aid/1268/fid/126>
with Mozilla, newest Opera and Safari you could try to use
XMLHttpRequest and read responseText (as long as you do not run into
encoding/decoding problems), then you could try to set innerHTML of an
existing element in the document.
 
M

McKirahan

McKirahan said:
Or build an array and "document.write" the join; as in:

var i = 0;
var a = new Array();
a(i++) = "<table border='1'>";
a(i++) = "<tr>";
a(i++) = " <td>Hello World!</td>";
a(i++) = "</tr>";
a(i++) = "</table>";
document.write a.join("\n");

Try this instead:

var html = [
"<table border='1'>",
"<tr>",
" <td>Hello World!</td>",
"</tr>",
"</table>",
""];
document.write(html.join(""));
 
L

Lasse Reichstein Nielsen

McKirahan said:
Try this instead:

... or while we are at it:

document.write("<table>",
"<tr>",
"<td>Hello World!<\/td>",
"</tr>",
"</table>");

/L
 
R

Random

Don't know how relevant it is to your specific needs, but I figured I'd
add a few alternatives in case you find them a little more palatable:


.... why not just use an iframe?
.... PHP include() can do this, too.
.... you might load it as content.htm in an invisible iframe, with an
onLoad that dumps document.body.innerHTML into the element where you're
wanting to drop this content. But IE sometimes dislikes this method.


The bad part of using JavaScript for this is that search engines WILL
NOT INDEX this content. Better to use an iframe or an include.
 
V

VK

You may use XMLHTTPRequest (google for it) in your script. This way you
can load internally your content file, pull out its body (or whatever
part you need) using DOM methods and insert it in any part of your
index page. It works in IE and FF, presumably in latest NN. In Safary
and Opera whis object is broken. Also be aware of security restrictions.
 
T

Thomas 'PointedEars' Lahn

Lasse said:
.. or while we are at it:

document.write("<table>",
"<tr>",
"<td>Hello World!<\/td>",
"</tr>",
"</table>");

But this, originating from client-side JavaScript v1.0 up to v1.3[1], is
less likely to be supported than the former is, it is proprietary, and
so should be deprecated. Both the MSDN Library[2] and W3C DOM Level 1+
HTML[3] define a different syntax, using only one argument for that method.
(I currently cannot test with IE, though.)


PointedEars
___________
[1]
<http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/document.html#1221642>
[2]
<http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/write.asp>
[3] <http://www.w3.org/TR/DOM-Level-1/level-one-html.html#method-write>
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75233634>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top