1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript in IE, Google Chrome en Firefox, online en off-line in jsrobowar

Discussion in 'JavaScript' started by Peter Uilenreef, May 6, 2013.

  1. #1
    An implementation of Robowars (http://robowar.sourceforge.net/RoboWar5/index.html) in Javascript (http://statico.github.io/jsrobowar/) is running online without problems in IE, Google Chrome and Firefox.

    The code can be downloaded from GitHub (https://github.com/statico/jsrobowar) as jsrobowar-master.zip.

    After unpacking the off-line program only runs in IE; Firefox shows error messages "errror compiling ..." , Google Chrome ".... error at line undefined, undefined at".

    It seems that the robotcode text files in the robots subdirectory IE only be read correctly in HTML TEXTAREA 's and transmitted to the robot code compiler in js / jsrobowar.js (see code fragment from js / gui.js)

    -------------------------------------------------- -----------------------------
    / / Load robot code into the editor when a robot is selected.
    select.change (function () {
    var name = $ (this) val ().;
    if (name) {
    var path = 'robots /' + name + 'txt.';
    textarea.val ((Loading '+ path +') ');
    textarea.attr ('disabled', 'disabled');
    $. get (path, function (src) {
    textarea.val (src);
    textarea.attr ("disabled", null);
    });
    }
    });
    -------------------------------------------------- ------------



    Cleaning up the javascript code in both files with JSLint and JSHint offers no solace.
    On Internet forums I found items about problems with TEXTAREA in Javascript, but as a newbie I found no solution there.

    I want to start a jsrobowar programming competition, and want to have a browser-independent implementation.

    Is there anyone who knows of this problem and has a solution for it?

    aTdHvAaNnKcSe.

    ôvô vriendelijke groet
    (\/)
    ^^ Peter Uilenreef
     
    Peter Uilenreef, May 6, 2013 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    You can't just open the file directly in the browser, the ajax requests are failing, and that is what is causing your problem. It has to be hosted, even on a local setup, you will need to have it served from a webserver. the XMLHTTPRequests are failing, because they are not allowed to load local files for security reasons. If you are using windows you could install WAMP or even just apache or any other web server to self host, and access the application in the browser like:
    http://127.0.0.1/jsrobowar-master/index.html
    Code (markup):
    and it will work cross browser.

    WAMP: http://sourceforge.net/projects/wampserver/
     
    shofstetter, May 16, 2013 IP