2014-12-23 49 views
0

我想用我的#play自定義按鈕播放我的iframe視頻。我已經將iframe放入引導響應式嵌入div中。我在看iframe中的正確內容嗎?我無法獲得使用jQuery播放的iframe視頻

JS:

$(document).ready(function ($) { 
    $('#play').click(function() {  //custom button id 
     $('iframe').contents().find('#wistia_video').get(0).play(); 
     $('.row.grey, .row.header').hide(); //hides elements over htevideo 
    }); 
}); 

HTML:

<div class="embed-responsive embed-responsive-4by3"> 
    <iframe src="//fast.wistia.net/embed/iframe/b4nym2w6dx" allowtransparency="true" 
frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" 
allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen 
msallowfullscreen width="595" height="253"></iframe>  
</div> 

的iFrame iports它的class和id動態,所以我不能張貼在這裏。

+0

跨域IFRAME? –

+0

是的,這是正確的。 – Dimoff

+0

所以閱讀:http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy –

回答

1

是的這是一個Cross Domain的問題。你最好使用Wistia API

我已經爲你工作JSFiddle

HTML

<script src="//fast.wistia.net/static/iframe-api-v1.js"></script> 
<div class="embed-responsive embed-responsive-4by3"> 
<iframe id="my_iframe" src="//fast.wistia.net/embed/iframe/b4nym2w6dx" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="595" height="253"></iframe> 
</div> 
<div id="play">Play</div> 

JS:

$(document).ready(function ($) { 
wistiaEmbed = document.getElementById("my_iframe").wistiaApi; 

$('#play').click(function() { //custom button id 
    wistiaEmbed.play(); 
    $('.row.grey, .row.header').hide(); 
}); 
}); 
+0

保持良好的工作!絕對做了這份工作。你能簡單地解釋一下你如何在元素ID上添加元素,這個東西是如何工作的? – Dimoff

+0

對不起,我可能沒有得到你的問題。您應該仔細閱讀Wistia API。有很多例子。如果您有意地延長您的問題,並更加專注於您想知道的每一個細節,我會盡力回答。 –