【问题标题】:Detect click in iframe and run script in parent (NOT same domain)检测 iframe 中的点击并在父级(不同域)中运行脚本
【发布时间】:2017-12-06 10:36:25
【问题描述】:

当 .gridlove-sidebar-action 在 iframe 中时,我想在 in parent 中运行脚本。 Iframe 不在同一个域中,但 AccessControlAllowOrigin 在 htaccess、css 和脚本中被“激活”,除此之外。如果 iframe 位于同一域中,则该脚本正在运行。我拥有这两个域。

内嵌框架:

<iframe id="followblog" src="http://example.com/iframe.html"></iframe>

在 iframe 中:

<span class="gridlove-sidebar-action">
    <a class="#" href="#">
    My button
    </a>        
</span>

在父级中运行的脚本:

$('#followblog').load(function(){

    var iframe = $('#followblog').contents();

    iframe.find(".gridlove-sidebar-action").click(function(){
        $('body').addClass('gridlove-sidebar-action-open gridlove-lock');
        $('.gridlove-sidebar-action-wrapper').css('top', gridlove_admin_top_bar_height);
    });
});

htaccess:

SetEnvIf Origin "http(s)?://(www\.)?(example.com)$" AccessControlAllowOrigin=$0$1
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true

【问题讨论】:

标签: javascript jquery html iframe


【解决方案1】:
// Defined in Parent window 
function defInParent(code){

}

// Call from Child iFrame 
window.opener.authSuccessWithCode(code);

【讨论】:

    猜你喜欢
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多