在iframe src中插入div

时间:2017-11-22 05:52:58

标签: javascript html iframe

 <iframe src='https://mywebsite.com/search?q=TEST'> </iframe>

<script type="text/javascript">
    var msgArr = new Array();
    msgArr[0] = "Message 1...";
    msgArr[1] = "Message 2...";
    msgArr[2] = "Message 3..."
    window.onload = function () {
        document.getElementById("msgDiv").innerHTML = msgArr[Math.floor(Math.random()*msgArr.length)];
    }
</script>
<div id="msgDiv"></div>

我可以将div msgDiv插入TEST吗?请有人帮帮我吗

1 个答案:

答案 0 :(得分:0)

假设您希望在iframe中插入内容;

注意:我在iframe中添加了'id';

<iframe src='https://mywebsite.com/search?q=TEST' id='iFrame'> </iframe>

var iframe = document.getElementById('iFrame').contentWindow.document;
iframe.open();
iframe.write('Content that u want to be inserted inside frame');
iframe.close();