Forum Moderators: open

Message Too Old, No Replies

Need to include external file in HTML

         

webmouse

3:15 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Sorry if this turns out to be a stupid question I'm a newbie to javascript.
Does javascript have a command comparable to the php command 'include'?

I have the need to change some variable settings without having to edit the html source. I was going to have a file that would look like:

var description1="#*$!xxx";
var description2="xxxxxx";

that could just be uploaded when some things need to be changed. Unfortunately the host of the website does not have database support, so I need to be able to upload a file that will allow for text on the webpage to be changed.

rocknbil

7:01 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you considered server side includes, and does your host support them?

<!-- #include virtual="/some_other_directory/file.txt" -->

or

<!-- #include file="same_directory_file.txt" -->

the file normally has to be named with an .shtml extension to be parsed so that the file is included.

webmouse

1:43 am on Feb 13, 2005 (gmt 0)

10+ Year Member



Thanks! I'll give that a try. After further research it looks as if I should also be able to do:
<script src=#*$!x.js ....>
also. Sorry, it does appear to be a stupid question. Thanks for the help.

Rambo Tribble

1:59 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might also wish to consider iframes, both for visible content and/or for invisible parameter passing. XMLHttpRequest is now supported by a number of popular browsers, and is considered by many to be the most efficient way to stay within the page's execution framework while dynamically retrieving data from the server. [developer.apple.com...]

SpaceFrog

8:13 am on Feb 14, 2005 (gmt 0)

10+ Year Member



I personnaly would not go for frames nor iframes and would just use external javascript files:

<script type="text/javascript" id="mydata" src="fileone.js"></script>

should you need to change to another source file with other values of variables:

document.getElementById('mydata').src='newfile.js'

Bernard Marx

8:27 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Changing the src of a SCRIPT element is really convenient, but it appears to only work in IE.

try this:
[jpspan.sourceforge.net...]

and wrt SCRIPT elements:
[dotvoid.com...]

Rambo Tribble

3:12 pm on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It was my understanding that this is a nonstandard behaviour on IE's part (can you imagine?), and that the specification calls for all scripts associated with a page to be available at load.

My only concern with XMLHttpRequest is that, to my understanding, in IE it is implemented as an ActiveX control. I would hope that most who still use IE to browse the web have ActiveX disabled, or at least hobbled.

Regarding iframes and quoting from Goodman's Dynamic HTML, Second Edition, "Because an iframe element draws its content from a separate server file, it may be used as a way to accomplish client-side 'includes'."