我想在iframe加载时添加一些html和javascript代码到iframe,这样,当用户上网时,它将通过iframe转到其他链接。
我试过了:
<script src="http://code.jquery.com/jquery-2.0.2.js"></script>
<body>
<button id='button1' onclick="changecode()">Change Code</button>
<iframe id='iframe1' name='iframe1' src='http://example.in/Default.aspx'> </iframe>
<script type="text/javascript">
function changecode(){
$('#iframe1').contents().find('div.xyz').load('2.html');
}
</script>
</body>
另一次javascript尝试:
<script type='text/javascript'>
function changecode() {
document.frames('iframe1').document
.getElementById('ContentPlaceHolder1_UpdatePanel1').innerHTML='11';
}
</script>
发布于 2013-07-10 14:20:30
load事件不会从文档的html元素触发,但您可以从框架本身附加一个加载处理程序:
<script type="text/javascript">
function changecode(){
$('#iframe1').load(function () {
$(this).contents().find('div.xyz').html('11');
});
}
</script>
https://stackoverflow.com/questions/17572996
复制相似问题