为什么form.submit()在IE9中失败,当iframe中的表单和用户通过gmail时



我创建了函数来发送带有指向我的网站的反向链接的电子邮件,我正在使用代码点火器框架

用户

单击电子邮件上的特定链接(反向链接)后,用户将重定向到具有iframe的"我的页面"。

我使用该iframe提交带有文件输入的表单,而无需刷新页面。

当用户在IE9浏览器中使用gmail通过该链接时,form.submit()功能失败,在其他浏览器中它可以正常工作,其他电子邮件(gmail除外)也是如此。

请帮助我找到解决方案

谢谢。

更新

实际上我正在使用 ajaxupload jquery 库,它在上述情况下form.submit();行失败

     /* Creates form, that will be submitted to iframe
     * @param {Element} iframe Where to submit
     * @return {Element} form
     */
    _createForm: function(iframe){
        var settings = this._settings;
        // We can't use the following code in IE6
        // var form = document.createElement('form');
        // form.setAttribute('method', 'post');
        // form.setAttribute('enctype', 'multipart/form-data');
        // Because in this case file won't be attached to request                    
        var form = toElement('<form method="post" enctype="multipart/form-data"></form>');
        form.setAttribute('action', settings.action);
        form.setAttribute('target', iframe.name);                                   
        form.style.display = 'none';
        document.body.appendChild(form);
        // Create hidden input element for each data key
        for (var prop in settings.data) {
            if (settings.data.hasOwnProperty(prop)){
                var el = document.createElement("input");
                el.setAttribute('type', 'hidden');
                el.setAttribute('name', prop);
                el.setAttribute('value', settings.data[prop]);
                form.appendChild(el);
            }
        }
        return form;
    },
    /**
     * Gets response from iframe and fires onComplete event when ready
     * @param iframe
     * @param file Filename to use in onComplete callback 
     */
    _getResponse : function(iframe, file){            
        // getting response
        var toDeleteFlag = false, self = this, settings = this._settings;   
        addEvent(iframe, 'load', function(){                
            if (// For Safari 
                iframe.src == "javascript:'%3Chtml%3E%3C/html%3E';" ||
                // For FF, IE
                iframe.src == "javascript:'<html></html>';"){                                                                        
                    // First time around, do not delete.
                    // We reload to blank page, so that reloading main page
                    // does not re-submit the post.
                    if (toDeleteFlag) {
                        // Fix busy state in FF3
                        setTimeout(function(){
                            removeNode(iframe);
                        }, 0);
                    }
                    return;
            }
            var doc = iframe.contentDocument ? iframe.contentDocument : window.frames[iframe.id].document;
            // fixing Opera 9.26,10.00
            if (doc.readyState && doc.readyState != 'complete') {
               // Opera fires load event multiple times
               // Even when the DOM is not ready yet
               // this fix should not affect other browsers
               return;
            }
            // fixing Opera 9.64
            if (doc.body && doc.body.innerHTML == "false") {
                // In Opera 9.64 event was fired second time
                // when body.innerHTML changed from false 
                // to server response approx. after 1 sec
                return;
            }
            var response;
            if (doc.XMLDocument) {
                // response is a xml document Internet Explorer property
                response = doc.XMLDocument;
            } else if (doc.body){
                // response is html document or plain text
                response = doc.body.innerHTML;
                if (settings.responseType && settings.responseType.toLowerCase() == 'json') {
                    // If the document was sent as 'application/javascript' or
                    // 'text/javascript', then the browser wraps the text in a <pre>
                    // tag and performs html encoding on the contents.  In this case,
                    // we need to pull the original text content from the text node's
                    // nodeValue property to retrieve the unmangled content.
                    // Note that IE6 only understands text/html
                    if (doc.body.firstChild && doc.body.firstChild.nodeName.toUpperCase() == 'PRE') {
                        doc.normalize();
                        response = doc.body.firstChild.firstChild.nodeValue;
                    }
                    if (response) {
                        response = eval("(" + response + ")");
                    } else {
                        response = {};
                    }
                }
            } else {
                // response is a xml document
                response = doc;
            }
            settings.onComplete.call(self, file, response);
            // Reload blank page, so that reloading main page
            // does not re-submit the post. Also, remember to
            // delete the frame
            toDeleteFlag = true;
            // Fix IE mixed content issue
            iframe.src = "javascript:'<html></html>';";
        });            
    },        
    /**
     * Upload file contained in this._input
     */
    submit: function(){                        
        var self = this, settings = this._settings;
        if ( ! this._input || this._input.value === ''){                
            return;                
        }
        var file = fileFromPath(this._input.value);
        // user returned false to cancel upload
        if (false === settings.onSubmit.call(this, file, getExt(file))){
            this._clearInput();                
            return;
        }
        // sending request    
        var iframe = this._createIframe();
        var form = this._createForm(iframe);
        // assuming following structure
        // div -> input type='file'
        removeNode(this._input.parentNode);            
        removeClass(self._button, self._settings.hoverClass);
        removeClass(self._button, self._settings.focusClass);
        form.appendChild(this._input);
        form.submit();
        // request set, clean up                
        removeNode(form); form = null;                          
        removeNode(this._input); this._input = null;            
        // Get response from iframe and fire onComplete event when ready
        this._getResponse(iframe, file);            
        // get ready for next request            
        this._createInput();
    }
};

检查代码是否在 iframe 中,如果没有在 form.submit() 中指定 iframe,即

document.iframename.form.submit();

最新更新