2014-03-03 102 views
1

我一直在試圖讓我的嵌入式YouTube播放列表在用戶通過網頁中的鏈接打開新的瀏覽器窗口時停止(最好是暫停)。此鏈接轉到另一個頁面,該頁面還會自動啓動視頻(沒有人希望同時播放兩個視頻)。這是我迄今爲止的裸骨代碼。謝謝您的幫助。在打開新的瀏覽器窗口時暫停Youtube視頻

<iframe width="452" height="278" src="//www.youtube.com/embed/videoseries?list=PL3NaSh-osYfmAc4IUijQN1aJGDehZepVQ&autoplay=1?enablejsapi=1" frameborder="0" allowfullscreen></iframe> 

回答

0

您可以看到鏈接onClick,call pause to the Youtube control並繼續打開鏈接。更多類似這樣的:

從鏈接中刪除href並設置一個#標記。設置一個id(讓我們假設是myLink)。 趕上鍊接點擊:

$("#myLink").click(function(e) { 
    //call pause on your Youtube control. See this response: http://stackoverflow.com/a/12522499/335905 
    // as long as you are not calling e.preventDefault(), the link should continue opening as expected. 

    }); 
+0

這裏的問題是,'window.open'被視爲一個彈出窗口,甚至可能開始會遭到封鎖。 – levi

+1

只要你不調用'e.preventDefault()',鏈接應該繼續按預期打開,所以'window.open'甚至可能不是必需的。 – levi

+0

對這兩個評論都是正確的。編輯並添加您的反饋,希望您不介意。 – celerno

相關問題