У меня на локальном сервере есть два файла index.html и lorem.txt. Хочу с помощью <iframe> загрузить содержимое файла lorem.txt в <div>. Но почему-то не получается. Что я делаю не правильно?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Untitled</title>
</head>
<body>
<div id="result"></div>
<button id="request">Request</button>
<script>
window.onload = function() {
var button = document.getElementById("request"),
div = document.getElementById('result');
button.addEventListener('click', function() {
var result = createIframe("f", "/lorem.txt");
div.innerHTML = result.contentWindow.document.body.innerHTML;
//result.parentNode.removeChild(result);
});
function createIframe(name, src, debug) {
var tmpElem = document.createElement('div');
tmpElem.innerHTML = '<iframe name="' + name + '" id="' + name + '" src="' + src + '">';
var iframe = tmpElem.firstChild;
iframe.style.display = 'none';
document.body.appendChild(iframe);
return iframe;
}
}
</script>
</body>
</html>