设置指向YouTube iframe视频的外部链接 [英] set external link to youtube iframe video

查看:542
本文介绍了设置指向YouTube iframe视频的外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站使用iframe you-tube视频。

I am using iframe you-tube video in my website.

示例代码:

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

如果我点击YouTube视频,它会重定向到外部页面。我使用了以下代码。

If I click the youtube video it will redirect to the external page. I used the below code.

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

我知道我的方法是错误的。它不工作。请确认这样做吗?

I know my way is wrong. It is not working. Please confirm to do this in anyway?

推荐答案

这不会工作。要解决你的问题,你必须使用javascript。作为参考,您可以检查以下主题
检测使用JavaScript

This will not work. To solve your problem you have to use javascript. For reference you can check following thread 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函数,其将使用户到期望的URL

Here I superimposed another div overiframe (we will not set any background for it, so iframe content will be seen) which will have onclick function which will take user to desired url

这篇关于设置指向YouTube iframe视频的外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆