[英]Inject code in to an iframe on load
我想在加載iframe時向其添加一些html和javascript代碼,以便在用戶上網時,它將通過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>
加載事件不會從文檔的html元素觸發,但是您可以從框架本身附加加載處理程序:
<script type="text/javascript">
function changecode(){
$('#iframe1').load(function () {
$(this).contents().find('div.xyz').html('11');
});
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.