-
March 9th, 2003, 03:25 PM
#1
Banned
JavaScript problem
looking for some javascript that will grab the contens of a txt file and save them to a variable.
this is for a website i want to create which loads html code into a layer to reduce overall loading times of my pages.
so far using dreamweaver i have this code...
----The button---
<b onClick="MM_setTextOfLayer('main','','this is the contact page')">Contact[/b]
---
---The Java produced by dw of which i understand 3/4---
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_setTextOfLayer(objName,x,newText) { //v3.0
if ((obj=MM_findObj(objName))!=null) with (obj)
if (navigator.appName=='Netscape') {document.write(unescape(newText)); document.close();}
else innerHTML = unescape(newText);
}
//-->
</script>
---
basically instead of "this is the contact page" i want to load html code from "contact.txt"
now all i need is a pointer on how to do this...
the only thing i don't know how to do is to get the contents of the txt file. i can define variables etc myself.
any help is welcomed. if you need me to clarify or rephrase my question please let me know.
thanx.
-
March 19th, 2003, 07:20 AM
#2
As far as I know, Javascript cant do includes or read/write another file. this is what server-side includes are for I guess.
SSI cant be done with JS, but it's not that hard using PHP or ASP.
Someone correct me if im wrong, long time since I was doing this sort of stuff
.sig - There never was a .sig?
I own a Schneider EuroPC with MS-Dos 3.3 and it works.
-
March 19th, 2003, 12:55 PM
#3
Banned
is there any file extention it could load from?
if you can make javascript files that can be read then can't i save my html code in that manner and retrive the data like that?
-
March 19th, 2003, 03:20 PM
#4
Well the only way I know of, wich isn't what you are looking for, is to include a script file, like this:
<script language="Javascript" src="globalscripts.js"></script>.
This way of including a script file is used for global scripts, and easy control of them.
This kind of include *could* be used for what you want, but i would not recommend it, and you would have to script everything with something like document.write();
As I said, it was a long time ago since i coded anything in JS so Im not really sure, but you should definitely check out Server Side Includes, check if your serverhost has PHP or ASP running, if they do, its a simple syntax.
.sig - There never was a .sig?
I own a Schneider EuroPC with MS-Dos 3.3 and it works.
-
April 24th, 2003, 09:03 PM
#5
Junior Member
Try this with Active X
You'll need to have Active X enabled in order to read the file though.
All you'll have to do is change the name and/or location of the file called "your_file.txt" below.
I hope this helps!
// This creates a new Active X Object in order to read in a file.
// Refer to the new variable as "file"
file = new ActiveXObject("Scripting.FileSystemObject");
// Sets the variable "f" to equal the new open file contents
f = file.OpenTextFile("c:\\your_file.txt", 1);
// This reads in a single line
line = f.ReadLine();
-
May 6th, 2003, 08:54 PM
#6
Junior Member
You can find several examples that you could possibly expand upon at www.javascriptsource.com .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|