Discussion in 'Javascript' started by naveen raj, Mar 25, 2012.

  1. naveen raj

    naveen raj Guest

    how to read from a file in the script ?
    naveen raj, Mar 25, 2012
    1. Advertisements

  2. naveen raj

    SAM Guest

    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


    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;

    not sure that works with IE

    Stéphane Moriaux avec/with iMac-intel
    SAM, Mar 25, 2012
    1. Advertisements

  3. naveen raj

    Scott Sauyet Guest

    naveen raj wrote:
    > 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
    Scott Sauyet, Mar 25, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.