access div in iframe parent

2019-01-14 17:39发布

问题:

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

回答1:

try this in iframe:

$('#DIVtobehidden', window.parent.document).hide();


回答2:

$("#element-In-Iframe").on('click', function() {
    $('#element-in-parent-window', window.parent.document).hide();
});

FIDDLE



回答3:

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