How to attach submit listener to all forms including those in iframes and nested iframes
问题 I want to attach an event listener to every form on my site so that when a form is submitted, a confirm box will pop up asking if the user is sure they want to proceed. If the user is not sure, I don't want the form to fire. So far I have this code: window.onload = function() { for(var i=0; i<document.forms.length; i++){ document.forms[i].addEventListener("submit",formSubmit,false); } } function formSubmit(e) { if (confirm("Are you sure?")) { return true; } return false; } Notes: I can't use