开发者

Bind to element within an iframe (same domain)

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜