4

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:

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.

At the line var text

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);
Justin Buergi
  • 131
  • 11

1 Answers1

0

I think you should load it with an AJAX request.

http://www.w3schools.com/jquery/ajax_get.asp

Or is the url elsewhere:

Get JSON data from external URL and display it in a div as plain text

Community
  • 1
  • 1
dec
  • 594
  • 1
  • 9
  • 18