H5环境中
js
window.location.href = "https://www.baidu.com"
// 或
window.open("https://www.baidu.com")- 注意:window.open在某些现代浏览器可能会被阻止,因为它常被广告商滥用
APP环境中
js
// 在APP内打开外部浏览器
plus.runtime.openURL('https://www.baidu.com');js
// 在APP内打开一个内置窗口打开页面,并自带标题栏和返回按钮
plus.runtime.openWeb('https://www.baidu.com');H5/APP:uni-link组件
html
<!-- H5中会打开新网页 -->
<!-- APP会打开外部浏览器 -->
<uni-link href="https://www.baidu.com">点击打开外部链接</uni-link>webview组件
html
<template>
<view v-if="src">
<!-- #ifdef H5 -->
<iframe width="100%" height="100%" :src="src" :title="title" />
<!-- #endif -->
<!-- #ifndef H5 -->
<web-view :webview-styles="wbStyles" :src="src" :fullscreen="false" />
<!-- #endif -->
</view>
</template>
<script>
export default {
data() {
return {
title: '百度搜索页',
src: 'https://www.baidu.com',
wbStyles: {
width: '100%',
height: '100%',
},
};
},
onLoad(option) {
this.title = option?.title;
this.src = option?.src;
},
};
</script>