b站iframe引用代码视频,js显示 隐藏 停止 播放 等控制功能

如图,把b站视频引入自己网站,是没法用js的方式实现播放暂停功能.来控制,因为他提示不同源,如下面的提示错误
Failed to read a named property ‘document’ from ‘Window’:
Blocked a frame with origin “” from accessing a cross-origin frame.
但我们可以用删除iframe的src地址的方式实现
代码示例


<style>

    img{width:100%;display:block;margin-bottom:5px;}  
	#about-page{background:#f5f5f5;padding-top:80px}
	video{width:100%;height:auto}
	
	 .div2,#float1{position:fixed;_position:absolute;
    top:45px;right:0; z-index:250;}
  button{float:right;display:block;margin:5px}
  #myVideoiframe{min-height:200px;width:100%}
</style>
 <section id="about-page">
    <div id="float1"style="margin:0 auto;display:none">
	<button onclick="showVideo()">显示视频</button>
	</div> 	
	
  <div id="float2"style="margin:0 auto;background:#000;">

<iframe id="myVideoiframe"src="//player.bilibili.com/player.html?isOutside=true&aid=113792071507929&bvid=BV111rYY1E5K&cid=27762820747&p=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe>
 <button onclick="pauseVideo()">关闭视频</button>

</div> 	      
    </section>

<input id="hide_input" type="hidden" style='opacity: 0'>
<script>
function pauseVideo() {
var iframe = document.getElementById('myVideoiframe');
var iframeSrc = iframe.src;
//alert(iframeSrc);
      $("#hide_input").val(iframeSrc);
	  iframe.src = '';
  $('#float2').stop().fadeOut();
  $('#float1').show();
}
function showVideo() {
var iframe = document.getElementById('myVideoiframe');
iframe.src = $("#hide_input").val();;

   $('#float2').show();
  $('#float1').stop().fadeOut();
}
</script>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值