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 11 of 11
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Reading a txt or xml file

    Is there any short and simple way I can get my JavaScript app to read a xml or txt file containing just something like 1.5.2 and compare it to variable version number var VersionNumber = "1.4.1"; then if it is a old version run a function? I have absolutely no idea how you would do this but it needs to be short and simple.

    Pez,

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    Code:
    function IO(U, V) {// A tiny ajax library.  2007, DanDavis
        var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        X.open(V ? 'PUT' : 'GET', U, !1);
        X.setRequestHeader('Content-Type', 'text/html')
        X.send(V ? V : '');
    return X.responseText;}
    
    function runMe(){
      alert ("running the update function");
     return true;
    }
    
    
    
    // ------------------------ customize below
    
    var oldVersion = "1.4.1";
    var newVersion = IO("text.txt");
    if(   oldVersion != newVersion ){  runMe(); }
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    Pezmc (06-12-2008)

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Would this work in firefox? It seems to be using the activeX protocol.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    Quote Originally Posted by Pezmc View Post
    Would this work in firefox? It seems to be using the activeX protocol.
    tested and working in ie 6 and 7, ff2 and 3, opera 9, and safari 3.

    i bet it works in others as well.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    Pezmc (06-12-2008)

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks for your help. It is really useful! Is there anyway to get this to read data on another site as the js is for greasemonkey so is locally stored and my server txt file is at:
    http://ikariamsolarium.googlecode.co...nk/version.txt

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    not with the code posted, but here is greasemonkey version

    in html page:
    Code:
    function gmCallBack(a){
         var oldVersion = "1.4.1";
         var newVersion = a;
         if(   oldVersion != newVersion ){  runMe(); }
    }
    
    gmCallBack.url = "http://ikariamsolarium.googlecode.com/svn/trunk/version.txt"

    in user script:
    Code:
    (function (callBack){ //one-way io (read) for grease monkey; by dandavis
       if(!callBack){return;}
    	GM_xmlhttpRequest({    method: 'GET',url: callBack.url,    headers: {
            'User-agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14',
            'Accept': 'text/plain,text/html,text/xml'},
    	onload: function(a){ callBack(a.responseText); } });
        return "data arrives as argument0 to window.gmCallBack";
    }(  unsafeWindow.gmCallBack    ))  //change this var to fetch multiple urls

    this works only once per page load, so copy the code to get multiple pages.
    you can cut and paste several copies of the user script code block in your script.
    change only the parenthesized text on the last line to a different html-page callback function name.
    Last edited by rnd me; 06-12-2008 at 05:43 AM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    Pezmc (06-12-2008)

  • #7
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts
    You just earned youself three thanks! You deserve it, this is now a critical part of my greasemonkey script. Would you like a
    //By Rnd_Me
    included before these functions as i would gladly include it!

    Edit: Where does the "in html page" stuff go?
    How do I actually start the function?

    Once again thanks!
    Last edited by Pezmc; 06-12-2008 at 10:33 AM.

  • #8
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Does anyone else know?

  • #9
    New Coder
    Join Date
    Jan 2007
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Bump: Sorry but I don't want this thread to die

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    Quote Originally Posted by Pezmc View Post
    Edit: Where does the "in html page" stuff go?
    How do I actually start the function?
    1
    in a script section, alongside your other code.
    directly after function runMe for instance...


    2
    you do not need to start the function.
    It is called by greaseMonkey when the remote URL's data arrives.




    glad to hear things are working well for you.

    I'll gladly take a "comment credit" in any code, thanks.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #11
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    dont lol use php it is easyer
    faster and alot less text just google it there are loads of tutorials


  •  

    Posting Permissions

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