1

我创建了发送带有指向我网站的反向链接的电子邮件的功能,我正在使用 codeigniter 框架

用户单击电子邮件上的特定链接(返回链接)后,用户重定向到我的具有 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();
    }
};
4

1 回答 1

0

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

document.iframename.form.submit();
于 2012-05-04T09:31:31.957 回答