網(wǎng)站首頁 編程語言 正文
web-view
Webview 是一個基于webkit引擎,可以解析DOM 元素,展示html頁面的控件,它和瀏覽器展示頁面的原理是相同的,所以可以把它當(dāng)做瀏覽器看待。(chrome瀏覽器也是基于webkit引擎開發(fā)的,Mozilla瀏覽器是基于Gecko引擎開發(fā)的)
開發(fā)過小程序的話對這個標(biāo)簽應(yīng)該比較熟悉,web-view標(biāo)簽與iframe標(biāo)簽類似,可以在我們的頁面中渲染第三方頁面
web-view標(biāo)簽的使用
與iframe標(biāo)簽類似
<iframe src="URL路徑"></iframe>
web-view:
<web-view src="URL路徑"></web-view>
web-view與iframe的區(qū)別
web-view標(biāo)簽?zāi)J(rèn)是占滿屏幕的且不能使用CSS改變樣式(例如在CSS設(shè)置height或者width),甚至web-view的層級是最高的,也就是說不能有元素可以顯示在web-view上
iframe標(biāo)簽則可以通過CSS設(shè)置寬或者高,我們可以將其他元素顯示在iframe標(biāo)簽上,例如(懸浮框組件)
設(shè)置web-view的高度
<template>
<view class="content">
<web-view src="https://www.baidu.com"></web-view>
<view class="header">
<text style="font-size: 40rpx;">標(biāo)題</text>
<u-icon name="share" size="40"></u-icon>
</view>
</view>
</template>
<script>
var wv;
export default {
data() {
return {
}
},
onReady() {
var self = this;
var currentWebview = this.$scope.$getAppWebview();
setTimeout(function() {
let h=720,top=70;
wv = currentWebview.children()[0]
uni.getSystemInfo({//獲取設(shè)備信息
success: function (res) {
h=res.windowHeight-top;
}
});
wv.setStyle({//設(shè)置web-view高度與web-view跟設(shè)備頂部的距離
top:top,
height:h,
})
}, 1000); //如果是頁面初始化調(diào)用時,需要延時一下
}
}
</script>
<style lang="less" scoped>
.header{
padding: 20rpx;
box-sizing: border-box;
width: 100vw;
height: 140rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
}
</style>
獲取當(dāng)前web-view的URL
<template>
<view class="content">
<web-view src="https://www.baidu.com"></web-view>
<view class="header">
<text style="font-size: 40rpx;">標(biāo)題</text>
<u-icon name="share" size="40" @click="show"></u-icon>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onReady() {
},
methods:{
show(){
var pages = getCurrentPages();
var page = pages[pages.length - 1];
var currentWebview = page.$getAppWebview();
console.log(currentWebview.children()[0].getURL());//獲取當(dāng)前web-view的URL
}
}
}
</script>
<style lang="less" scoped>
.header{
padding: 20rpx;
box-sizing: border-box;
width: 100vw;
height: 140rpx;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
}
</style>
原文鏈接:https://blog.csdn.net/qq_44849271/article/details/125754493
相關(guān)推薦
- 2022-12-24 kali2021.4a使用virtualenv安裝angr的詳細(xì)過程_其它綜合
- 2022-12-19 Oracle?數(shù)據(jù)庫啟動過程的三階段、停庫四種模式詳解_oracle
- 2023-10-16 forEach方法如何跳出循環(huán)和for方法跳出循環(huán)
- 2021-12-11 C++嵌入式內(nèi)存管理詳情_C 語言
- 2023-10-15 element-ui里el-progress:進(jìn)度條問題的解決Invalid prop: custo
- 2022-09-14 python與xml數(shù)據(jù)的交互詳解_python
- 2022-05-27 python繪制棉棒圖的方法詳解_python
- 2024-03-08 學(xué)習(xí)基于ssm框架前后端分離實(shí)現(xiàn)注冊登錄MD5加密的心得體會
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支