使用 jQuery 按鈕單擊更改 iFrame 的 URL? (Change URL of iFrame with jQuery button click?)


問題描述

使用 jQuery 按鈕單擊更改 iFrame 的 URL? (Change URL of iFrame with jQuery button click?)

我試圖弄清楚如何在單擊藍色按鈕後更改此 iframe 中的視頻。因此,換句話說,單擊藍色按鈕將更改 iframe 中正在播放的視頻。

如果有人知道如何做到這一點,請告訴我...

http://jsfiddle.net/69nj13nL/

HTML

<div id="stage">
            <iframe width="560" height="315" src="https://www.youtube.com/embed/e‑ORhEE9VVg" frameborder="0" allowfullscreen></iframe>
</div>

<br>

<div id="button">Click me</div>

CSS

#button{
    background:blue;
    cursor:pointer;
    width:200px;
    margin‑left:auto;
    margin‑right:auto;
    color:white;
}

jQuery

$(document).on('click', '#button', function(event) {


});   

參考解法

方法 1:

Consider this:

$( "#button" ).click(function() {
    $("#stage > iframe").attr("src", "http://www.wp.pl");
});

Where http://www.wp.pl is just a link for you to replace. You can always try to do it with somekind of loop to get more songs.

(by m0aPatNowak)

參考文件

  1. Change URL of iFrame with jQuery button click? (CC BY‑SA 2.5/3.0/4.0)

#iframe #jquery #youtube






相關問題

IE6 iframe 渲染問題 (IE6 iframe rendering issue)

Cross Domain JavaScript parent location setting firefox error (Cross Domain JavaScript parent location setting firefox error)

Перанакіраванне ад даччынага акна да бацькоўскага ў iframe з дапамогай javascript (OAuth) (Redirecting from child window to parent to a iframe using javascript (OAuth))

Tương tác với trình phát youtube được nhúng của học viện Khan (Interacting with Khan academy's embedded youtube player)

創建文件並將其加載到 iframe (creating file and load it in iframe)

Firefox 無法訪問同一域上的 iframe 打印 (Firefox can't access iframe print on the same domain)

如何在特定情況下處理 iframe。如何處理 iframe 內容? (How to handle iframe in particular situation. How to handle iframe contents?)

使用 jQuery 按鈕單擊更改 iFrame 的 URL? (Change URL of iFrame with jQuery button click?)

如何使網頁只允許 iframe 訪問 (How to make web page only allowed accessed by iframe)

為什麼 Internet URL 在 iframe 標記中不起作用? (Why is an Internet URL not working in an iframe tag?)

Word 2007 文件啟動新窗口而不是顯示內聯 (Word 2007 files launching new window instead of displaying inline)

有沒有辦法在 <IFrame> 中嵌入網站,如果它拒絕嵌入? (Is there any way to embed a website in <IFrame>, If it is denying to be embedded?)







留言討論