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
Add a ment  | 

2 Answers 2

Reset to default 4

When 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