当.gridlove-sidebar-action在iframe中时,我想在父中运行脚本。 iframe不在同一个域,但AccessControlAllowOrigin在htaccess中被“激活”,除此之外,css和脚本正在运行。如果iframe在同一个域中,则脚本正在运行。我拥有这两个域名。
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
答案 0 :(得分:0)
// Defined in Parent window
function defInParent(code){
}
// Call from Child iFrame
window.opener.authSuccessWithCode(code);