I've got an iframe which i'm dynamically inserting into the page. Then I want to bind to a button within that iframe to trigger a page refresh on the parent page.
Is this possible? Both are on the same domain.
$('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('cli开发者_StackOverflowck',function() {
alert('cleared!');
window.location.reload();
});
I think if you just make:
window.location.reload();
==> window.parent.location.reload();
you can achieve the described functionality.
although, if the code is running in the outer window then your code should already work because the window
in scope is that of the parent. Have you tried it yet?
EDIT: ok, this is probably easier to do without 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);
精彩评论