2017-07-03 2 views
0

Ich würde gerne das Skript in Eltern ausführen, wenn .gridlove-sidebar-Aktion in Iframe ist. Iframe ist nicht in der gleichen Domäne, aber AccessControlAllowOrigin ist in htaccess "aktiviert", css und Skript funktioniert außer diesem. Das Skript funktioniert, wenn iframe in derselben Domäne ist. Ich besitze die zwei Domänen.Detect Klick in iframe und Skript in Eltern (nicht die gleiche Domäne)

Iframe:

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

Im Iframe:

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

Script in Mutter auszuführen:

$('#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

Sie müssen 'jQuery' verwenden iframe' contents() 'Konzept: - https://Stackoverflow.com/a/13782102/4248328 –

+2

Bitte lesen Sie dies: https://stackoverflow.com/questions/726816/ how-to-access-iframe-übergeordnete-page-using-jquery –

+0

Ich habe die Frage bearbeitet – user1708580

Antwort

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

} 

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