这是我的 iframe HTML 代码:
<ul id="titleee" >
<li><a href="http://adskpak.com/?type=2&id=jayvicious">CLick me</a></li>
</ul>
这是我的主页代码:
<iframe id="iframe" src="iframe1.php"></iframe>
<script>
$(document).ready( function(){
$('#iframe').contents().find('#titleee').click();
});
</script>
似乎没有触发点击事件。
最佳答案
只需检查浏览器的控制台是否有错误:-
您可能会收到此错误:-
SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://www.goibibo.com" from accessing a cross-origin frame.
如果您父级和 iframe 位于同一域,则此方法有效。将页面和 iframe 的 document.domain 设置为相同的值,即您的域,然后检查。
关于javascript - 跨 iframe 触发点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27577133/