我有一个包含HTML页面的iframe。现在我想要获得单击的父项目的类。
这是我ifram:获取iframe中点击标签的父母
<iframe src="//example.com" id="frame" ></iframe>
是css:
#frame{ width:380px; height:420px;}
这是我的脚本:
$(document).ready(function() {
var iframe = document.getElementById('frame');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document.body;
$(innerDoc).on('click', function(e) {
var thisID = ((e.target).id);
alert(thisID);
alert(innerDoc.getElementById(thisID));
$(thisID).click(function() {
var Allclassnames = $(thisID).parent();
console.log(Allclassnames);
});
});
});
,但回报的项目被点击only.how修复它?
演示:DEMO
NOTE
:这些都是在下面DEMO
同一domain.maybe不工作了这reason.but我敢肯定,我的HTML是我的网站同一个域的内部。 谢谢。
是的,他们在同一个域 –