当前位置:网站首页>H5 开发内嵌页面跨域问题
H5 开发内嵌页面跨域问题
2022-08-04 15:19:00 【qq_45689385】
问题
有一个内嵌外部网页的需求,而页面内嵌进来出现跨域,从而进行一系列尝试
解决思路
由于是H5开发,当时内嵌用的是iframe,想起移动端有一个webview,webview的权限比iframe的高,就想着用webview尝试一下,但是发现最终浏览器把webview还是解析成为了iframe,于是自己写了一个demo,在原生环境下运行测试了一下webview,发现并未出现跨域问题,于是想着那我像app壳子那样用plus动态创建一个webview呢,应该不会被解析成iframe了把,测试过后,发现成功解决
解决代码逻辑
mounted() {
if (window.plus) { // 判断是否又plus
this.plusReady();
} else {
document.addEventListener('plusready', this.plusReady, false);
}
},
methods: {
plusReady() {
this.ws = plus.webview.currentWebview(); // 动态创建一个当前窗口
this.createWebview();
},
createWebview(){
// 创建webview this.src:地址 embed:id名称
let embed = plus.webview.create(this.src, 'embed', {
top: '58px',
bottom: '0px',
position: 'dock'
});
this.embed = embed;
// 添加到当前窗口
this.ws.append(embed);
}
},
// 组件销毁时清除,解决返回后,webview窗口未销毁返回导致遮挡原页面的问题
destroyed() {
// 从webview实例中移出
this.ws.remove(this.embed);
// 清除
this.embed.removeFromParent();
this.embed.close();
}
边栏推荐
猜你喜欢
随机推荐
【Today in History】August 4: First female Turing Award winner; NVIDIA acquires MediaQ; first Cybersecurity Challenge completed
洛谷题解P1028 数的计算
leetcode:212. 单词搜索 II
从-99打造Sentinel高可用集群限流中间件
FTP协议抓包-工具wireshark与filezilla
Http-Sumggling缓存漏洞分析
Semaphore 基本原理
明明加了唯一索引,为什么还是产生重复数据?
基于 Next.js实现在线Excel
JCMsuite Application: Oblique Plane Wave Propagation Transmission Through Aperture
AOSP built-in APP franchise rights white list
IP第十八天笔记
Oracle database user creation, restart, import and export
1403. 非递增顺序的最小子序列
7 天找个 Go 工作,Gopher 要学的条件语句,循环语句 ,第3篇
什么,你告诉我?作用域也分种类?
tif转mat
基于 Next.js实现在线Excel
Next -20- 使用自定义样式 (custom style)
IP报文头解析