简体   繁体   English

无法检测jQuery单击vimeo iframe

[英]Can't detect jQuery click on vimeo iframe

Simple Vimeo iframe click does not work: 简单的Vimeo iframe点击不起作用:

$('iframe').click(function(){
    alert('ok');
});

I've also tried: 我也尝试过:

$('body').click(..
$(document).on('click','iframe',..

But when user clicks video while hovering it, nothing works, it just plays the video. 但是,当用户在悬停视频时单击视频时,没有任何效果,它只是播放视频。

if you include the query parameter api=1 in your embed code, you can access events, including those events triggered when the user clicks the video in the iframe (play,pause). 如果您在嵌入代码中包含查询参数api=1 ,则可以访问事件,包括用户在iframe中点击视频(播放,暂停)时触发的事件。 You'll also probably want to include their froogaloop.js file to more easily access these events. 您可能还希望包含其froogaloop.js文件,以更轻松地访问这些事件。

<iframe id="player1" src="http://player.vimeo.com/video/27855315?api=1&player_id=player1" width="400" height="225"></iframe>

它是iframe中的第三方domian,由于相同的原产地政策 ,您无法执行此操作。

try this: 尝试这个:

$('iframe').contents()
           .find('[src*="vimeo.com"]')
           .click(
               function(){
                  alert('foo');
               }
            );

I found that before I could get anything inside the iframe to be found I needed to determine if the iframe was loaded. 我发现,在能够找到iframe中的任何内容之前,我需要确定iframe是否已加载。 Then if the iframe gets loaded after page load or reloaded later in the process, your click function works. 然后,如果在页面加载后加载iframe或稍后在此过程中重新加载iframe,您的click函数就会起作用。

jQuery('#iframe').load(function() {
   jQuery('#iframe').contents().find('#play-button').click(function () {
        // do your stuff
    });
}

** this may or may not work cross-domain, but determining if the iframe loaded can be used as a hackish method of determining if something has happened in the iframe. **这可能跨域也可能不起作用,但是确定是否可以将加载的iframe用作确定iframe中是否已发生故障的方法。 If you created a "play" button on your domain on top of the iframe it could be used to load the iframe via a click function after page load and then your load function could contain your slideshow pause. 如果您在iframe上方的域上创建了一个“播放”按钮,则可用于在页面加载后通过点击功能来加载iframe,然后您的加载功能可能会包含幻灯片暂停。

Unfortunately, you cannot track clicks in cross-domain iframes due to same origin policy, as epascarello has previously said. 遗憾的是,由于采用了相同的来源政策,因此您无法跟踪跨域iframe中的点击次数,如epascarello先前所说。

You could set up a "thumbnail" that the user clicks, which would pull up that popup and then subsequently replace the thumbnail with the actual video. 您可以设置用户单击的“缩略图”,这将弹出该弹出窗口,然后将缩略图替换为实际视频。 Just embed the video you want, but keep it as a hidden div, then use .show() when you want it to start playing. 只需嵌入所需的视频,但将其保留为隐藏的div,然后在要开始播放时使用.show()

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM