前端在app页面中打开外接h5页面的方法
window.open,window.location.href,iframe
·
方法
1.iframe,
2.window.location.href,
3.window.open
1.用iframe加载页面
<div class="page">
<iframe
frameborder="0"
:src="activityUrl"
width="100%"
:height="this.pageHeight"
scrolling="yes"
id="iframe"
></iframe>
</div>
data () {
return {
activityUrl:'' // h5地址
}
}
mounted() {
this.pageHeight = document.body.clientHeight
this.activityUrl = 'https://www.baidu.com/' //需要跳转的h5地址
}
.page {
overflow-x: hidden;
}
1.1 局限性,当对方页面设置安全策略时,出现一下效果
安全策略----(可以使web服务不允许 iframe 引用)
X-Frame-0ptions HTTP 响应头是用来给浏览器指示允许一个页面可否在 frame, iframe 或者 obiect 标签 中展现的标记。网站可以使用此功能,来确保自己网站的内容没有被嵌到别人的网站中去,也从而避免了点击劫持(clickjacking)的攻击。
// 如下
add header X-Frame-Options"SAMEORIGIN"
1.2局限性2
1.由于h5页面是镶嵌在app–h5页面中,那么对面h5做一些交互的时候,就要先跟我方h5交互,再去调用app客户端的方法,多了一次交互,麻烦
2.用window方法 不用单独去设置一个页面,可以直接点击打开新的页面,
// 2.1
window.location.href = 'https://www.baidu.com/'
// 2.2
window.open = 'https://www.baidu.com/'
1.app(客户端) --A(我方h5) --B(要跳转的h5),在与B页面交互时,这两种方法不用通过我方h5-- A页面,比如页面标题,箭头返回上一步,或者返回指定页面等等
2.两者对比
Location.href属性是对当前浏览器窗口的URL地址对象的参考;window.open()方法打开一个新的窗口。
Location.href属性一般用于页面的迭代,也就是重新定位当前页
window.open()方法可以通过新开窗口或者说新开标签页打开一个网址,而location.href属性只能在当前页打开一个网址
更多推荐
已为社区贡献2条内容
所有评论(0)