473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SSI with JavaScript

How can I include a file using JavaScript?

document.write('<!--#include file="myfile.htm" -->')

won't work because of the commenting. Is there a way to fool
JavaScript into including the file at the appropriate point?

Currently I am calling iframes instead of using SSI. You can see why
I'd want to switch.

If it cannot be done with SSI, is there another inclusion format that
will work?

(For those who want to chastise me for using JavaScript at all, rest
assured I am not abusing it and that the appropriate <noscript> tags
are in use.)
Jul 20 '05 #1
6 8971
Jane Withnolastname wrote:
How can I include a file using JavaScript?

document.write('<!--#include file="myfile.htm" -->')

won't work because of the commenting. Is there a way to fool
JavaScript into including the file at the appropriate point?
XmlHttpRequest
(For those who want to chastise me for using JavaScript at all, rest
assured I am not abusing it and that the appropriate <noscript> tags
are in use.)

--
Iso.
FAQs: http://html-faq.com http://alt-html.org http://allmyfaqs.com/
Recommended Hosting: http://www.affordablehost.com/
Web Design Tutorial: http://www.sitepoint.com/article/1010
Jul 20 '05 #2
Jane Withnolastname <Ja**********************@yahoo.com> wrote:
How can I include a file using JavaScript?

document.write('<!--#include file="myfile.htm" -->')

won't work because of the commenting.


Uh no. It won't work because JavaScript is handled by the browser and
SSIs are handled by the server. So by the time the JavaScript is
parsed it is far too late for the SSI to be parsed.

It may help if you gave a bit more background. Why does this file need
to be included by JavaScript, why can it not just be included once?

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #3
On Mon, 29 Sep 2003 10:05:18 +0100, Steve Pugh <st***@pugh.net> wrote:
Jane Withnolastname <Ja**********************@yahoo.com> wrote:
How can I include a file using JavaScript?

document.write('<!--#include file="myfile.htm" -->')

won't work because of the commenting.


Uh no. It won't work because JavaScript is handled by the browser and
SSIs are handled by the server. So by the time the JavaScript is
parsed it is far too late for the SSI to be parsed.

It may help if you gave a bit more background. Why does this file need
to be included by JavaScript, why can it not just be included once?

Steve


OK.
When I list something on eBay, I add it to my web page. That's easy.
But I don't want to have to be there and on the ball in order to take
it off my web page when the auction ends. Therefore, I use a
JavaScript to "expire" it at the proper time.
If the auction is not over, the script shows the iFrame. If the
auction is over, it reverts to just an eBay button (which is what
noscript browsers see anyway).
Ideally, I want to rid myself of iFrames, but without SSI, I cannot
figure out how to get another page into my main page.
Maybe I'm asking for the impossible. If that's the case, I guess I'm
stuck with the iFrames - which I hate just as much as everyone else
here!
Thanks.
Jul 20 '05 #4
On Mon, 29 Sep 2003 09:32:01 +0000, Isofarro
<sp*******@spamdetector.co.uk> wrote:
Jane Withnolastname wrote:
How can I include a file using JavaScript?

document.write('<!--#include file="myfile.htm" -->')

won't work because of the commenting. Is there a way to fool
JavaScript into including the file at the appropriate point?


XmlHttpRequest


I'm sorry, I don't know what that means.
Can you elaborate? Or point me in the direction of a tutorial that
will further explain this or tell me how to implement it?
Unless I'm missing something, this is XML, rather than HTML. Is it
much different? Or can it be included in a HTML document?
(I bet that made me look really stupid, but I have absolutely no
experience with XML and, frankly, it scares me. But if it solves my
problems, I will do it.)
Jul 20 '05 #5
Sometime around Thu, 02 Oct 2003 02:22:44 GMT, Jane Withnolastname is
reported to have stated:
OK.
When I list something on eBay, I add it to my web page. That's easy.
But I don't want to have to be there and on the ball in order to take
it off my web page when the auction ends. Therefore, I use a
JavaScript to "expire" it at the proper time.


That could be done fairly easily via SSI and some server-side scripting
(PHP, ASP, etc).

--
Mark Parnell
http://www.clarkecomputers.com.au
Jul 20 '05 #6
Jane Withnolastname wrote:
On Mon, 29 Sep 2003 09:32:01 +0000, Isofarro
<sp*******@spamdetector.co.uk> wrote:
Jane Withnolastname wrote:
How can I include a file using JavaScript?

document.write('<!--#include file="myfile.htm" -->')

won't work because of the commenting. Is there a way to fool
JavaScript into including the file at the appropriate point?
XmlHttpRequest


I'm sorry, I don't know what that means.
Can you elaborate?


XmlHttpRequest is an object in both Internet Explorer 5+ browsers and
Mozilla based browsers. It allows a page to request resources over HTTP.

<http://jibbering.com/2002/4/httprequest.html>
<http://www.15seconds.com/issue/020606.htm>
<http://www.xulplanet.com/references/elemref/ref_XMLHttpRequest.html>
<http://www.scottandrew.com/weblog/2002_04#a000257>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmobjxmlhttprequest.asp>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmobjpmexmlhttprequest.asp>
Unless I'm missing something, this is XML, rather than HTML.
It allows any sort of data to be transferred, not just XML.
Is it
much different? Or can it be included in a HTML document?
Script using XmlHttpRequest functions is within the page, it requests an
external resource - be it XML, HTML, plain text, whatever.

Then just insert that into the document at the correct place using DOM
techniques such as getElementById() and appendChild().

DOM reference:
<http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html>

This is what I do here:
http://www.isolani.co.uk/atomClient/atomClient.html

Select an option from the drop down list, and click "Get Blog Entries", this
fires off a request for an XML document and extracts a list of entries
which dynamically populates the next page which is the "Entries from
selected server:" page.

(I bet that made me look really stupid, but I have absolutely no
experience with XML and, frankly, it scares me. But if it solves my
problems, I will do it.)


You don't need to use XML if you don't want to. As long as you send the data
in a manner you can insert it in the right place, then the data can be of
any format. I chose XML because that was the format the data I needed to
work with was already in.
--
Iso.
FAQs: http://html-faq.com http://alt-html.org http://allmyfaqs.com/
Recommended Hosting: http://www.affordablehost.com/
Web Design Tutorial: http://www.sitepoint.com/article/1010
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.