从 iframe 本身中删除父级的 iframe

remove an iframe from parent from within the iframe itself

本文关键字:iframe 删除      更新时间:2023-09-26

我在域A中有一个iframe。

<iframe id="iframeid" src="domain-B/abc.php"  scrolling="no" allowTransparency="true" frameborder="0" style="top: 0%; width:100%;height:100%;left:0;overflow:auto;position: fixed;z-index: 100000;text-align:center;line-height:normal;_position: absolute;"></iframe>

abc.php有一个带有十字按钮的div,只要单击该十字按钮,我就使用jquery隐藏了div。div 被删除,但父页面不可点击(因为 iframe(

我想在单击十字按钮后立即删除整个 iframe,以便再次单击父页面。我知道这是一个跨域问题,我见过很少类似的问题,但我无法找到解决方案。

将此添加到父级:

function childClose() {
    $('#iframeid').remove();
}

然后从 iFrame 中调用它:

document.domain = 'domain.com';
$('selector').click(function(){parent.childClose();});

但是,是的,如果域不同,这将不起作用。