防止iframe连接重定向到父级页面

原文:https://www.douban.com/note/586337871/


iframe页面的链接是可以让父级页面重定向的,如:


页面A

<body>
<h1>hello</h1>
<iframe src='b.html'></iframe>
</body>


页面B


<body>
<h1>hi</h1>
<a href="http://www.baidu.com" target="_top">
</body>

在这种情况下,当我们在页面A中点击iframe页面B的链接,就会让整个页面的请求链接改变

iframe中的sandbox属性可设置iframe页面中的链接不重定向到父级页面

在PC端:

<iframe src="b.html" sandbox="allow-forms allow-scripts allow-same-origin allow-popups">
</iframe>


在移动端:

<iframe src="b.html" sandbox="allow-forms allow-scripts allow-same-origin">
</iframe>



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值