I have an iframe that is a target for a form. The iframe should remove the main element when submit is pressed. This works as expected in all major browsers except Firefox, where main is removed immediately on page load.
Is this just a bug in Firefox, or am I missing something?
document.addEventListener("DOMContentLoaded", _ => {
// Create an iframe and submit a form to it
// ========================================
const form = document.forms[0]
form.setAttribute("target", "Response")
const iframe = Object.assign(document.createElement("iframe"), {
name: "Response"
})
iframe.hidden = true
document.body.appendChild(iframe)
iframe.addEventListener("load", () => {
const main = document.querySelector("body > main")
main.remove()
iframe.hidden = false
})
})
<main>
<form action=https://script.google.com/macros/s/AKfycbzz-KveHder1A3CX8GcqZI6GR2MQj66PDRWNKoatIET_LXNqQs/exec method=get>
<fieldset>
<legend>Foobar</legend>
<label><input type=radio name=Foobar value=Foo>Foo</label><br>
<label><input type=radio name=Foobar value=Bar>Bar</label><hr>
<input type=submit value=Submit>
</fieldset>
</form>
</main>