国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 14:44:29
字體:
來源:轉載
供稿:網友

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

需要在本頁面中展示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>

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

復制代碼 代碼如下:

<iframe id="dialogFrame" frameborder="0" scrolling="no" style="background-color:transparent; position: absolute; z-index: -1; width: 100%; height: 100%; top: 0;left:0;"></iframe>

不過html5有新的dialog元素用于對話框。

iframe的一些方法:

獲取iframe內容:

 var iframe = document.getElementById("iframe1"); var iwindow = iframe.contentWindow; var idoc = iwindow.document;  console.log("window",iwindow);//獲取iframe的window對象  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

自適應 iframe:

即1去掉滾動條,2設置寬高

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

例子:

復制代碼 代碼如下:
<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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三原县| 清流县| 茌平县| 宜川县| 彭水| 黄平县| 龙山县| 宝清县| 革吉县| 牙克石市| 军事| 葵青区| 屯留县| 鸡东县| 肥东县| 明溪县| 沽源县| 巴楚县| 江孜县| 保靖县| 台南县| 普兰店市| 韩城市| 轮台县| 绥中县| 武穴市| 广南县| 灵寿县| 孟州市| 辉县市| 巫溪县| 麻城市| 宝山区| 靖宇县| 汉沽区| 瓮安县| 福鼎市| 区。| 海安县| 静安区| 阜平县|