access div in iframe parent

2019-01-14 17:19发布

I have a page which contains an iframe to another page, what I am looking for is to click something inside the iframe, which can then access or more specifically hide a div in the parent. I know some JQuery but for some reason just sit there blankly at the code editor when I try to write it on my own

3条回答
小情绪 Triste *
2楼-- · 2019-01-14 17:25

try this in iframe:

$('#DIVtobehidden', window.parent.document).hide();
查看更多
smile是对你的礼貌
3楼-- · 2019-01-14 17:43
$("#element-In-Iframe").on('click', function() {
    $('#element-in-parent-window', window.parent.document).hide();
});

FIDDLE

查看更多
仙女界的扛把子
4楼-- · 2019-01-14 17:46

If both pages are on the same (sub)domain you should be able to access the parent window with:

window.parent.document.getElementById('divId')

Well this is without jQuery but should work

查看更多
登录 后发表回答