Javascript only works when javascript console is open on chrome

I have a script (javascript) that works in firefox but not in chrome or IE. I opened chromes debug console to find the problem. No errors are reported and the code works perfectly. Running it again with the console closed does not work again.

I verified that the version of the script is correct (not old and cached). The console does not report any warnings or errors.

  • How do I throttle $http requests in angularjs?
  • How to get class from HTML stocked in a var?
  • Serve a static JSON object file in rails
  • good php framework for fully ajax-based web applications?
  • Smoothstate.js: Preventing header from reloading, despite these links triggering the page change
  • sencha apps slows down on rendering on ui thread
  • I tried putting in simple logging that writes to a div at the bottom of the page – no information.
    (in the debug console it works – including logging info in the div).

    The function is the callback after an XMLHttpRequest is made to the server.

    I verified that the php script is called by including error_log calls. The error_log shows the return value correctly. A page refresh also show the row has been deleted.

    It appears as if the function removeRow() is never called unless the console is open. (method or reserved words conflict??) Tried changing the function name to delRow (including callback) – still not working.

    All other Ajax calls seem to work fine.

    A Code snippet follows:

    var pos = 0;
    var xhr;
    function eraseRow() {
       var myImage = this;
       var fullid =;
       // split row no and record id eg 5_1223 => row=5 and recordid=1223
       var idComponents = fullid.split("_");
       if (idComponents.length > 1) {  // check if image has complete row info
          rowid = idComponents[1]; // extract row number from id
          pos = parseInt(idComponents[0]);
          xhr = new XMLHttpRequest(); // only support IE8 or +
          xhr.onreadystatechange = removeRow;
    function removeRow() {
       if (xhr.readyState == 4) {
          if (xhr.status == 200) {
             var err = document.getElementById("errormsg");
             var str = xhr.responseText;
             err.innerHTML = "Server returned "+str;
             if (str === "go-ahead") {
                var table = document.getElementById("tableid");

    PHP (valid_del.php):

    if (isset($_GET['delrow']) && strlen($_GET['delrow'] > 0) {
       $recid = $_GET['delrow'];
       $db = createDbConn(); // function that connects to mysql server db
       $result = $db->query("delete from doclibrary where doc_id='$recid'");
       if ($result===true) {
          echo 'go-ahead';
          error_log('Script successful - returns go-ahead',0);
       } else {
          echo 'stop';
          error_log('Script not successful - returns stop',0);
    } else {
       echo 'stop';
       error_log('Script not given record id - returns stop',0);

  • ajax/php file download not working?
  • What should i choose? jquery, mootools, yui, scriptaculous or prototype?
  • How do I access an array value correctly within a callback function?
  • “pushing” changes in a database to a web page without refreshing
  • Will google index the correct URL for hashbang/escaped_fragment content
  • Facebook live feed functionalty?
  • One Solution collect form web for “Javascript only works when javascript console is open on chrome”

    I think the DOM is not ready, try to add your code calls into window.onload, or in $(document).ready if you are using JQuery.