title: How do I read the contents of a .dat file in javascript?
body: <p>I have a .dat file that is filled with lines of numbers I need for my program, but I've so far been unable to access the file by any method except inputting it after the code runs.  My latest try was the code below, but it returned the error: </p>
  
  <p>Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.</p>
  
  <p>At the line var text</p>
  
  <pre><code>var iframe = document.createElement('iframe');
  iframe.id = 'iframe';
  iframe.style.display = 'none';
  document.body.appendChild(iframe);
  document.domain = "yourdomain.com";
  iframe.src = 'hw2_files/example.dat.js';
  setTimeout(function(){
      var text = document.getElementById('iframe').contentDocument.body.firstChild.innerHTML;
      alert(text);
  }, 1000);
  </code></pre>