|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
JS - Load File --- Local Or Remote
I have been looking for a while, but I could never find a valid, pure JS example.
I have a file, on my server, say "updates.txt", that updates refrequently. (not really, just pretend). I have been trying to code a Java Script to load that file via a form button, and output the contents to say a textarea, or even the InnerHTML of my DIV block. Anyone know how? Thanks! |
|
#2
|
|||
|
|||
|
RE: JS - Load File --- Local Or Remote
Well, a few hours more of working/search for one. Here is 1 way of doing it. JS doesn't seem to have a reload "loadFile" that you can call.
Code:
<SCRIPT LANGUAGE="JavaScript">
var nn4 = (document.layers);
var nn6 = (document.getElementById && !document.all);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
function loadPage(id,nestref,url) {
if (nn4) {
var lyr = (nestref)? eval('document.'+nestref+'.document.'+id) : document.layers[id]
lyr.load(url,lyr.clip.width)
}
else if(ie4) parent.contentFRM.location = url;
else if(ie5 || nn6) document.getElementById('contentFRM').src = url;
setTimeout('showPage("contentLayer")',1000);
}
function showPage(id) {
if (ie4) {
document.all[id].innerHTML = parent.contentFRM.document.body.innerHTML;
}
else if(nn6 || ie5) {
document.getElementById(id).innerHTML = window.frames['contentFRM'].document.body.innerText;
}
}
</script>
</HEAD>
<BODY onload="parent.showPage('contentLayer')">
<a href="javascript:loadPage('contentLayer',null,'load-html-demo.html')">Load Page</a>
<iframe name="contentFRM" id="contentFRM" width="0" height="0" frameborder="0" src="load-html-demo.html">
</iframe>
<div id="contentLayer" style="position:absolute; width:345px; height:115px; z-index:1; left: 186px; top: 304px"></div>
Then create a file called "load-html-demo.html", and paste in what ever you want. I found it on http://javascriptsource.com .. Sightly modified some! |
|
#3
|
|||
|
|||
|
RE: JS - Load File --- Local Or Remote
look at the xml HTTP Request Object in javascript
i wanted to do the same thing you wanted, and after searching around i found they have something suited exactly to this. me personally, i thought it would be cool to have message boards use it. instead of re-downloading the entire html page to view the next page of posts, you could use js to swap the inner html w/ the new data, all in the background. it could even be preloaded, for near instant page to page views |
|
#4
|
|||
|
|||
|
RE: JS - Load File --- Local Or Remote
heres a demo
http://developer.apple.com/internet/webcontent/XMLHttpRequestExample/example.html |
|
#5
|
|||
|
|||
|
RE: JS - Load File --- Local Or Remote
Thanks for that link. It is what I was looking for, now the fun part of trying to remember why I had wanted to do that!
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > JS - Load File --- Local Or Remote |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|