vue框架中使用iframe内嵌网页,并且双击实现网页全屏放大

vue框架中使用iframe内嵌网页,并且双击实现网页全屏放大

利用Iframe插入网页

<iframe ref="iframe" src="https://www.taobao.com" frameborder="0" scolling="no"></iframe>

如果出现网页拒绝访问的情况可能与跨域有关,我在一开始的时候使用百度网址也被拒绝访问,后用淘宝网址嵌入成功。frameborder=0是不要边框, scolling="no"是不需要侧边滚动条,如有需要自行修改


双击实现iframe内嵌网页的双击放大过程

这个地方在实现过程中出现了很多问题,一开始想使用

this.$refs.iframe.width = document.documentElement.clientwidth
this.$refs.iframe.height = document.documentElement.clientheight

获取页面的值来实现全屏显示,但是后面运行代码时发现无法实现,原因如下:
打开的标签页中不只包含一个页面,iframe指向页面的document.documentElement.clientWidth不再等于浏览器宽度,而是等于iframe的宽度
https://www.cnblogs.com/nov5026/p/4630499.html


具体实现

template部分

        <div class="Test">
            <i class="el-icon-plus" @dbclick="fullScreen"></i>
            <iframe ref="iframe" src="https://www.taobao.com" frameborder="0" scolling="no"
              :style="{ width: isFullScreen ? '100%' : width, height: isFullScreen ? '100%' : height, backgroundColor: black }">
            </iframe>
        </div>

data部分

data(){
  return{
    isFullScreen: false,
  }
}

beforedestroy部分

document.removeEventListener('fullscreenchange', this.fullscreenchange)

mounted部分

document.addEventListener('fullscreenchange', this.fullscreenchange)

methods部分

    fullscreenchange(e) {
      if (document.fullscreenElement == null) {
        this.isFullScreen = false
      }
    },
    fullScreen() {
      if (this.isFullScreen) {
        document.webkitCancelFullScreen()
      } else {
        this.$refs.iframe.requestFullscreen()
      }
      this.isFullScreen = !this.isFullScreen
    },

希望自己多多学习,坚持记录问题和解决办法 加油!(这是第一次使用markdown,感觉还不错啊~)

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值