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
您需要使用'jQuery' iframe'contents()'概念: - https://stackoverflow.com/a/13782102/4248328 –
請閱讀此:https://stackoverflow.com/questions/726816/ how-to-access-iframe-parent-page-using-jquery –
我編輯了問題 – user1708580