2017-07-03 49 views
0

當.gridlove-sidebar-action在iframe中時,我想在父級中運行腳本Iframe不在同一個域,但AccessControlAllowOrigin是「激活」在htaccess中,CSS和腳本除了這個工作。如果iframe在同一個域中,該腳本正在工作。我擁有這兩個領域。檢測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 
+1

您需要使用'jQuery' iframe'contents()'概念: - https://stackoverflow.com/a/13782102/4248328 –

+2

請閱讀此:https://stackoverflow.com/questions/726816/ how-to-access-iframe-parent-page-using-jquery –

+0

我編輯了問題 – user1708580

回答

0
// Defined in Parent window 
function defInParent(code){ 

} 

// Call from Child iFrame 
window.opener.authSuccessWithCode(code); 
相關問題