title: how do I use a blob read from a file in an if/else statement?
body: <p>I am trying to read a character from a localhost file (a downloaded html file) and use it in an if/else statement.</p>
  
  <p>This is code I found online with only modest modifications.  It successfully targets the specified character and displays it when clicking one of the buttons, but when I try to use it in the if/else statement (by clicking the action button), I have no success.  What should happen, is the if/else statement uses the character to determine how to ammend the window.open statement in the var mywin.  I'm not sure how to use the blob in the if/else statement. Thank you for your help.</p>
  
  <p>'function job()' is where I am stuck.  </p>
  
  <p>Here is the code to the source file (a downloaded html webpage)</p>
  
  <pre><code> &lt;small&gt;&lt;a href="http://192.168.089/30000"&gt;&lt;/a&gt;&lt;/small&gt;&lt;a href="http://192.168.089/30000/0101101001011010"&gt;0101101001011010&lt;/a&gt;&lt;p&gt;
  </code></pre>
  
  <p>Here is the code of the html file I am writing that is trying to use the if/else statement.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;script&gt;
    function job(){
  var action;
    if (blob = '0') {
      action = '06';
    } else {
      action = '05';
    } 
       var mywin = window.open('http://192.168.0.89/30000/' +action,'','');
        setTimeout(function() { mywin.close();}, 3000);
      }
    &lt;/script&gt;
  &lt;style&gt;
    #byte_content {
      margin: 5px 0;
      max-height: 100px;
      overflow-y: auto;
      overflow-x: hidden;
    }
    #byte_range { margin-top: 5px; }
  &lt;/style&gt;
  &lt;input type="file" id="files" name="file" /&gt; Read bytes: 
  &lt;span class="readBytesButtons"&gt;
    &lt;button data-startbyte="89" data-endbyte="89"&gt;Relay 1&lt;/button&gt;
    &lt;button data-startbyte="90" data-endbyte="90"&gt;Relay 2&lt;/button&gt;
    &lt;button data-startbyte="91" data-endbyte="91"&gt;Relay 3&lt;/button&gt;
    &lt;button data-startbyte="89" data-endbyte="104"&gt;All Relays&lt;/button&gt;
    &lt;button&gt;entire file&lt;/button&gt;
  &lt;input type=submit value='Action' onclick='job();' /&gt;
  &lt;/span&gt;
  &lt;div id="byte_range"&gt;&lt;/div&gt;
  &lt;div id="byte_content"&gt;&lt;/div&gt;
  &lt;script&gt;
    function readBlob(opt_startByte, opt_stopByte) {
      var files = document.getElementById('files').files;
      if (!files.length) {
        alert('Please select a file!');
        return;
      }
      var file = files[0];
      var start = parseInt(opt_startByte) || 0;
      var stop = parseInt(opt_stopByte) || file.size - 1;
      var reader = new FileReader();
      // If we use onloadend, we need to check the readyState.
      reader.onloadend = function(evt) {
        if (evt.target.readyState == FileReader.DONE) { // DONE == 2
          document.getElementById('byte_content').textContent = evt.target.result;
          document.getElementById('byte_range').textContent = 
              ['Read bytes: ', start + 1, ' - ', stop + 1,
               ' of ', file.size, ' byte file'].join('');
        }
      };
      var blob = file.slice(start, stop + 1);
      reader.readAsBinaryString(blob);
    }
    document.querySelector('.readBytesButtons').addEventListener('click', function(evt) {
      if (evt.target.tagName.toLowerCase() == 'button') {
        var startByte = evt.target.getAttribute('data-startbyte');
        var endByte = evt.target.getAttribute('data-endbyte');
        readBlob(startByte, endByte);
      }
    }, false);
  &lt;/script&gt;
  </code></pre>