Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post

    loading text documents

    hi, how would i load a text document to a variable?
    Kris Hubby
    kwhubby site

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    a bit west of pittsburgh
    Posts
    236
    Thanks
    1
    Thanked 0 Times in 0 Posts
    im afraid javascript cant do that with *.txt files, but a good alternative would be *.js files.

    example:

    variables.js:
    --------------------------
    var name="Joe Frambach"
    var favSite="http://www.codingforums.com"
    var lang="Javascript"
    --------------------------


    the head of your html page:
    --------------------------
    <script language='javascript' src='variables.js'></script>
    <script...>
    alert(name + "\'s favorite site is " + favSite + ", and his favorite language is " + lang + ".")
    </script>
    --------------------------

    *.js files can also incluse functions etc.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    shoulnd you be able to get a text document into an iframe, and load the iframe outertext into a variable
    Last edited by kwhubby; 02-21-2003 at 05:56 AM.
    Kris Hubby
    kwhubby site

  • #4
    New to the CF scene
    Join Date
    Feb 2003
    Location
    Dublin
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The easiest way to do it would be use Server Side Includes. Have a look at Big Nose Bird the articles there have lots of SSI info.

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    I was able to get it to work
    with a hidden div tag, with an iframe to the source of a text document, than difine a variable to getElementsByTagName('HTML')[0].innerText
    of the iframe name, and wa la, I get the text of a text document into a variable using html/javascript


    Kris Hubby
    kwhubby site

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I wouldn't rely on that personally - afaik only ie5.5, ie6 and mozilla will let you do that; moz also splits the text into nodes every x bytes (can't remember what x is), whereas in IE it's all in childNodes[1]

    But really... you shouldn't rely on a text document having a DOM at all. The best way to import client-side data into javascript is to keep the data in XML.
    Last edited by brothercake; 02-22-2003 at 05:24 AM.

  • #7
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    I don;t really care at all about netscape or opera or anything else besides ie 5-6

    does ie split the data up too???...
    Kris Hubby
    kwhubby site

  • #8
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by kwhubby
    I don;t really care at all about netscape or opera or anything else besides ie 5-6
    That's a shame.

    And no, IE does not split the data up. It keeps it all in one TextNode.
    Last edited by jkd; 02-22-2003 at 07:00 AM.

  • #9
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    this is for main use on my computer, not really for wide sharing with the few netscape users out there (greatly increasing because of aol swapping to moz)
    Kris Hubby
    kwhubby site


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •