查看下面的代碼片段。我希望iframe中的輸出文本顯示在#source div中。我很努力,並對任何想法表示感謝。如何將iframe中的輸出文本複製到div? (劇本寫道: 「能看到的文字!」 在DIV #show如果格#sourcediv包含 「文本」,否則 「不能見文!」。)記住如何將iframe內容複製到div?
<html>
<body>
<div id="source"></div>
<div id="show"></div>
<script>
if (document.getElementById('source').innerHTML.indexOf("Text") != -1)
{document.getElementById('show').innerHTML="Can see text!";}
else{document.getElementById('show').innerHTML="Cannot see text!";}
</script>
<iframe id="iframe" src="http://majaulrika.esy.es/text.txt">
</body>
</html>
是iframe的域是一樣的您的網站?如果沒有,你可以改變iframe的網站內容嗎?答案不是,所以你不能。 –
@Mosh Feu iframe的域名與我的網站相同。 – mud
我建議不要使用iframe,這不再是1999年。現在,他們有一個有用的目的,即異步文件上傳。由於你標記的PHP,嘗試['file_get_contents()'](http://php.net/manual/en/function.file-get-contents.php) – Xorifelse