简体   繁体   English

Iframe中的表单未使用jQuery在IE11中提交

[英]Form within Iframe not submitted in IE11 using Jquery

From below code, the alert function should be executed after the form submit.But it executes at first time, after that it won't.It executes fine in all browsers except IE11. 从下面的代码中,警报功能应在表单提交后执行,但它会在第一次执行,之后便不会执行。它在除IE11之外的所有浏览器中都能正常运行。

Code: 码:

<iframe id="iframeID">
<form id="profile">
<input type="file" id="UPLOADED_FILE" name="UPLOADED_FILE" value="" >
<input type="submit" name="save_photo" value="Save" onclick="pressUpload();">
</form>
</iframe>

function pressUpload() {
    var iframe_document = document.getElementById('iframeID').contentWindow.document;
    var form_profile = $(iframe_document).find('#profile');
    var file_input_field = $(form_profile).find('input[name=UPLOADED_FILE]');

    $(file_input_field).bind('change', function () {
        var value = $(this).val();

        if (value) {

            $(form_profile).submit();


            if (navigator.userAgent.indexOf("MSIE") > -1 && !window.opera) {
                iframe.onreadystatechange = function () {
                    if (iframe.readyState == "complete") {

                        alert("HI");
                    }
                };
            }
        }
    })
}

That is invalid way to write markup. 那是写标记的无效方法。 but you should not use any element between iframe's opening/closing tags like you have done in your case. 但您不应像在您的案例中那样在iframe的开始/结束标记之间使用任何元素。

Actually that only gets executed when this element is not supported in any browser. 实际上,只有在任何浏览器均不支持此元素时才执行该操作。 @MDN you can see the example1 @MDN可以看到example1

<iframe src="page.html" width="300" height="300">
 <p>Your browser does not support iframes.</p>
</iframe>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM