溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

vue組件中使用iframe元素的示例代碼

發(fā)布時(shí)間:2020-10-04 04:36:17 來(lái)源:腳本之家 閱讀:303 作者:深淵上的火 欄目:web開發(fā)

本文介紹了vue組件中使用iframe元素的示例代碼,分享給大家,具體如下:

需要在本頁(yè)面中展示vue組件中的超鏈接,地址欄不改變的方法:

<template>
 <div class="accept-container">
   <div class="go-back" v-show="goBackState" @click="goBack">GoBack</div>
<ul>
 <li v-for="item in webAddress">
  <a :href="item.link" rel="external nofollow" target="showHere" @click="showIframe">{{item.name}}</a>
 </li>
</ul>
<iframe v-show="iframeState" id="show-iframe" frameborder=0 name="showHere" scrolling=auto src=""></iframe>
 </div>
</template>
<script>
export default {
 name: 'hello',
 data () {
 return {
  iframeState:false,
  goBackState:false,
  webAddress: [
  {
   name:'segmentFault',
   link:'https://segmentfault.com/a/1190000004502619'
  },
  {
   name:'博客',
   link:'http://vuex.vuejs.org/'
  },
  {
   name:'特效',
   link:'http://www.yyyweb.com/377.html'
  }
  ]
 }
 },
 mounted(){
 const oIframe = document.getElementById('show-iframe');
 const deviceWidth = document.documentElement.clientWidth;
 const deviceHeight = document.documentElement.clientHeight;
 oIframe.style.width = deviceWidth + 'px';
 oIframe.style.height = deviceHeight + 'px';
 },
 methods:{
 goBack(){
  this.goBackState = false;
  this.iframeState = false;
 },
 showIframe(){
  this.goBackState = true;
  this.iframeState = true;
 }
 }
}
</script>
<style scoped>
</style>

需要使同層元素不被覆蓋,可以加

復(fù)制代碼 代碼如下:

<iframe id="dialogFrame" frameborder="0" scrolling="no" ></iframe>

不過(guò)html5有新的dialog元素用于對(duì)話框。

iframe的一些方法:

獲取iframe內(nèi)容:

 var iframe = document.getElementById("iframe1");
 var iwindow = iframe.contentWindow;
 var idoc = iwindow.document;
  console.log("window",iwindow);//獲取iframe的window對(duì)象
  console.log("document",idoc); //獲取iframe的document
  console.log("html",idoc.documentElement);//獲取iframe的html
  console.log("head",idoc.head); //獲取head
  console.log("body",idoc.body); //獲取body

自適應(yīng) iframe:

即1去掉滾動(dòng)條,2設(shè)置寬高

var iwindow = iframe.contentWindow;
var idoc = iwindow.document;
iframe.height = idoc.body.offsetHeight;

例子:

復(fù)制代碼 代碼如下:
<iframe id="google_ads_frame2" name="google_ads_frame2" width="160" height="600" frameborder="0" src="target.html" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true"></iframe>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI