[英]Bind to element within an iframe (same domain)
我有一個 iframe 動態插入到頁面中。 然后我想綁定到 iframe 中的一個按鈕來觸發父頁面上的頁面刷新。
這可能嗎? 兩者都在同一個域上。
$('body').append('<iframe id="cacheBuster" src="http://lol.com/system/page.aspx" style="position: absolute; top:0; right:0; width: 20px; height: 20px; background: #fff" frameborder="0"></iframe>');
var cacheIframe = $('#cacheBuster');
cacheIframe.live('mouseover', function() {
$(this).stop().animate({ width : 300, height : 300});
});
cacheIframe.contents().find('#buttonid').live('click',function() {
alert('cleared!');
window.location.reload();
});
我想如果你只是做:
window.location.reload();
==> window.parent.location.reload();
您可以實現所描述的功能。
但是,如果代碼在外部 window 中運行,那么您的代碼應該已經可以工作,因為window
中的 window 是父代碼。 你試過了嗎?
編輯:好的,如果沒有 jquery,這可能更容易做到。
var ifr = document.createElement('iframe');
ifr.src = "http://google.com/";
document.body.appendChild(ifr);
button = ifr.contentDocument.createElement('a');
button.onclick = "window.parent.location.reload();" //you could prob use jquery here
ifr.contentDocument.body.appendChild(button);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.