javascript

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
    1. Advertising

  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

    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

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

  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
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mcdeveloper
    Replies:
    1
    Views:
    4,173
    mcdeveloper
    Jun 13, 2006
  2. CRON
    Replies:
    24
    Views:
    200,471
    Adrienne Boswell
    Jun 20, 2006
  3. Mark Rae

    JavaScript or not JavaScript

    Mark Rae, Sep 5, 2006, in forum: ASP .Net
    Replies:
    36
    Views:
    1,069
    Paul Sture
    Sep 9, 2006
  4. Nathan Sokalski
    Replies:
    4
    Views:
    570
    PJ on Development
    Nov 8, 2007
  5. Lisa Calla
    Replies:
    0
    Views:
    263
    Lisa Calla
    Nov 9, 2004
Loading...

Share This Page