admin管理员组文章数量:1292601
<iframe sandbox="allow-forms allow-scripts allow-same-origin" src="HTML_HERE" id="iframe"></iframe>
This is the sandboxed iframe, you are not allowed to modify this and add 'allow-downloads' or any sandbox properties. You need Javascript to sove this.
<iframe sandbox="allow-forms allow-scripts allow-same-origin" src="HTML_HERE" id="iframe"></iframe>
This is the sandboxed iframe, you are not allowed to modify this and add 'allow-downloads' or any sandbox properties. You need Javascript to sove this.
Share Improve this question asked Jun 22, 2020 at 4:03 MLSNKMLSNK 211 gold badge1 silver badge2 bronze badges 2- you just wanted this iframe to be viewable, and not allow users to make any changes to it? – Faiz Hameed Commented Jun 22, 2020 at 4:16
- ..............yup ............. – MLSNK Commented Jun 25, 2020 at 2:04
2 Answers
Reset to default 4When I make an iframe with those attributes, I am absolutely able to download a file (may not work on SO, but if you copy the code to a local file and try it, see what happens):
<iframe sandbox="allow-forms allow-scripts allow-same-origin" id=f ></iframe>
<textarea id=t>
<a id=u></a>
<button id="dao">Do it!?</button>
<script>
dao.onclick = () => {
console.log("hi")
u.href = URL.createObjectURL(
new Blob([
"hello there, just testing!?"
])
)
u.download = "hi.txt"
u.click()
}
</script>
</textarea>
<script>
f.src = URL.createObjectURL(
new Blob([
t.value
], {
type: "text/html"
})
)
</script>
'allow-downloads' is newly introduced value for the sandbox attribute in the iframe.
sandbox="allow-downloads"
Reference: https://developer.mozilla/en-US/docs/Web/HTML/Element/iframe#browser_patibility
本文标签: htmlHow can I allow download in sandboxed iframe using JavascriptStack Overflow
版权声明:本文标题:html - How can I allow download in sandboxed iframe using Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741559379a2385356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论