javascript

S

SAM

Le 25/03/12 09:29, naveen raj a écrit :
how to read from a file in the script ?

not possible

you must pass the text "to read" in a variable

then you can try to get the file

example

file to read : 'txt_1.js'
var t = 'Hello World';

reading :
<button onclick="newText('txt_1.js'); alert(t);">read 1</button>



function newText(url) {
var s = document.createElement('SCRIPT');
s.src = url;
document.body.appendChild(s);
}

not sure that works with IE
 
S

Scott Sauyet

naveen said:
how to read from a file in the script ?

Can you clarify what you're trying to do? The security policy of
browsers make it difficult if not impossible to read a file from the
user's local machine. But server-side scripts, and some browser
techniques can allow for it. Moreover, there are easy ways to read
from URLs on the same domain as a web page. Those URLs often map to
server-side files.

So what is it you're after?

-- Scott
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top