<div id="dd">132</div>
<script>
var s = '<iframe src="javascript:document.open();document.write(\'<script>alert(1);<\/script><div>test</div>\');document.close();"></iframe>';
document.getElementById("dd").innerHTML = s
</script>
<iframe id="tst" name="tst" ></iframe>
<script>
alert(2);
var cw = window.document.getElementById('tst').contentWindow;
cw.document.open();
cw.document.write('<script>alert("test")<' + '/script>');
cw.document.write('<div>test</div>');
cw.document.close();
</script>
IE6,IE7,FF2下測試通過
2.自適應高度
在id為"ifr"的iframe內容裏寫上js代碼:
<script>
function resize(){
parent.document.getElementById('ifr').style.height = document.body.scrollHeight>300?document.body.scrollHeight:300+"px";
}
window.onload=resize;
window.onresize = resize;
</script>
就能控制id為"ifr"高度至少為300px
要是回答的內容有問題,或認為不妥,請發送百度消息給我,消息內容加上本頁網址哦。。
·