2012-11-21 93 views
0

我在我的網站中使用iframe you-tube視頻。將外部鏈接設置爲youtube iframe視頻

示例代碼:

<iframe width="414" height="270" src="samplecode" frameborder="0" allowfullscreen></iframe> 

如果我點擊YouTube視頻會重定向到外部頁面。我使用了下面的代碼。

<a href="#"> <iframe width="414" height="270" src="samplecode" frameborder="0" allowfullscreen></iframe></a> 

我知道我的方式是錯誤的。它不工作。無論如何請確認要這樣做?

回答

1

這不起作用。要解決你的問題,你必須使用JavaScript。僅供參考,您可以檢查以下螺紋 Detect Click into Iframe using JavaScript

另一種解決方案是

<div style="position:relative"> 
<div style="position:absolute;width:414px;height:270px" onclick='window.location.href="http://google.com"' ></div> 
<iframe width="414" height="270" src="samplecode" frameborder="0" allowfullscreen></iframe> 
</div> 

我在這裏疊加另一個DIV overiframe(我們將不設置任何背景,所以iframe中的內容可以看出),這將具有的onclick功能,將用戶帶到所需的網址