Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery处理HTML5iFrame中的用户点击_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript 使用jQuery处理HTML5iFrame中的用户点击

Javascript 使用jQuery处理HTML5iFrame中的用户点击,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我试图在一个已经在生产的网站上展示一个新功能。因此,我使用iframe将此网站加载到我的开发服务器中,如下所示: <!DOCTYPE html> <html lang="en"> <head> </head> <body> <iframe id="myframe" src="https://production_website.com" style="border:none;" width="100%" height="600

我试图在一个已经在生产的网站上展示一个新功能。因此,我使用iframe将此网站加载到我的开发服务器中,如下所示:

<!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>
 <iframe id="myframe" src="https://production_website.com" style="border:none;" width="100%" height="600" seamless></iframe>
</body>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
     <script>
        console.log($("#myframe").contents());
        $("#myframe").contents().find(".importantContent").click(function(){
         console.log($(this));
        });
     </script>
</html>

console.log($(“#myframe”).contents();
$(“#myframe”).contents().find(“.importantContent”)。单击(函数(){
log($(this));
});
我试图在iframe区域拦截用户对特定DOM元素的点击,基于此,我将注入特定的HTML内容来演示一个特性。但是使用jquery click()进行侦听不起作用

有什么建议吗

我知道同源策略限制,但对于无法控制服务器的web设计师/开发人员来说,难道没有像使用插件禁用限制这样的解决方法吗


示例:

我在另一个线程中找到了这个答案,看起来它可能对您有用。尝试:

$('#myframe').load(function(){

    var iframe = $('#myframe').contents();

    iframe.find(".importantContent").click(function(){
           alert("test");
    });
});

另外,您有$(“#reco”).contents()而不是$(“#myframe”).contents(),您是否打算不使用本例中的iframe?

在同源策略中不会发生。我确信控制台有错误消息可以备份。@epascarello谢谢你的提示!我知道这个限制。我想知道我是否可以出于演示的原因禁用javascript中的安全功能,并在以后激活它,这样行吗?你可以通过更改其配置来禁用浏览器中的安全功能,但不能神奇地禁用其他所有浏览器。@epascarello是的,我只想让它在我的浏览器上运行以展示一项功能。