【发布时间】:2015-12-24 15:15:48
【问题描述】:
我有一个 .dat 文件,其中填充了我的程序所需的数字行,但到目前为止,除了在代码运行后输入它之外,我无法通过任何方法访问该文件。我最近的尝试是下面的代码,但它返回了错误:
未捕获的安全性错误:无法从“HTMLIFrameElement”读取“contentDocument”属性:阻止具有“null”来源的框架访问具有“null”来源的框架。协议、域和端口必须匹配。
在行 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);
【问题讨论】:
标签: javascript html getelementbyid appendchild createelement