Javascript 围绕iframe包装href
我想在vimeo或youtube视频周围包装一个href,并阻止嵌入的默认播放单击事件,只需转到href即可。有人知道怎么做吗Javascript 围绕iframe包装href,javascript,jquery,iframe,href,Javascript,Jquery,Iframe,Href,我想在vimeo或youtube视频周围包装一个href,并阻止嵌入的默认播放单击事件,只需转到href即可。有人知道怎么做吗 <a href="http://tumblr.com" target="_blank" class="linkwrap"> <iframe width="420" height="315" src="https://www.youtube.com/embed/5Xbs60BMeRU" frameborder="0" allowfullscree
<a href="http://tumblr.com" target="_blank" class="linkwrap">
<iframe width="420" height="315" src="https://www.youtube.com/embed/5Xbs60BMeRU" frameborder="0" allowfullscreen></iframe>
</a>
html
使用div作为覆盖,并用a标记将其包围。阅读本文了解如何为youtube实现div和使用不透明:
我认为有了这些信息,您应该可以做您想做的事情。要获得跨浏览器支持,请使用以下内容:
<div style="position:relative;">
<iframe width="420" height="315" src="https://www.youtube.com/embed/5Xbs60BMeRU" frameborder="0"></iframe>
<a href="http://tumblr.com" target="_blank" style="position:absolute; bottom:0; left:0; display:inline-block;"><img src="https://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png" width="420px" height="315px"></a>
</div>
我觉得值得一提的是,在我的例子中,在iFrame上添加
指针事件:none
允许链接使用如下结构
<div>
<a href="#test">
<iframe [ATTRIBUTES]></iframe>
</a>
</div>
…如果您使用JavaScript并单击
a
元素应用stopPropagation
,可能会有所帮助。
<div style="position:relative;">
<iframe width="420" height="315" src="https://www.youtube.com/embed/5Xbs60BMeRU" frameborder="0"></iframe>
<a href="http://tumblr.com" target="_blank" style="position:absolute; bottom:0; left:0; display:inline-block;"><img src="https://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png" width="420px" height="315px"></a>
</div>
<div>
<a href="#test">
<iframe [ATTRIBUTES]></iframe>
</a>
</div>