为什么form.submit()失败IE9,当iframe中的表单和用户通过gmail [英] Why form.submit() is fails IE9 , when form in iframe and user coming through gmail

查看:508
本文介绍了为什么form.submit()失败IE9,当iframe中的表单和用户通过gmail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的函数发送电子邮件与我的网站的反向链接,我使用codeigniter框架



后用户点击该电子邮件的特定链接,用户重定向到我的具有iframe的页面。



我使用iframe提交一个具有文件输入的表单,并刷新页面。



当用户在IE9浏览器中使用gmail浏览链接时, form.submit()函数失败,浏览器和其他电子邮件(除了gmail)。



请求帮助我找到解决方案



谢谢



实际上我使用的是ajaxupload jquery库,它在上面

form.submit(); > / *创建表单,将提交到iframe
* @param {Element} iframe提交的位置
* @return {Element} form
* /
_createForm:function (iframe){
var settings = this._settings;

//我们不能在IE6中使用下面的代码
// var form = document.createElement('form');
// form.setAttribute('method','post');
// form.setAttribute('enctype','multipart / form-data');
//因为在这种情况下文件不会附加到请求
var form = toElement('< form method =postenctype =multipart / form-data> form>');

form.setAttribute('action',settings.action);
form.setAttribute('target',iframe.name);
form.style.display ='none';
document.body.appendChild(form);

//为每个数据键创建隐藏的输入元素
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;
},
/ **
*准备好时从iframe获取响应并触发onComplete事件
* @param iframe
* @param文件在onComplete回调中使用的文件名
* /
_getResponse:function(iframe,file){
//获取响应
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>';){
//第一次,不要删除
//我们重新加载到空白页,以便重新加载主页
//不重新提交帖子

if(toDeleteFlag){
//修复FF3中的忙状态
setTimeout(function(){
removeNode(iframe);
},0);
}

return;
}

var doc = iframe.contentDocument?iframe.contentDocument:window.frames [iframe.id] .document;

//修复Opera 9.26,10.00
if(doc.readyState&& doc.readyState!='complete'){
// Opera触发加载事件多次
//即使DOM尚未准备好
//此修复程序不应影响其他浏览器
return;
}

//修复Opera 9.64
if(doc.body&& doc.body.innerHTML ==false){
// In Opera 9.64事件第二次触发
//当body.innerHTML从false
//更改为服务器响应约。 1秒后
return;
}

var response;

if(doc.XMLDocument){
// response是一个xml文档Internet Explorer属性
response = doc.XMLDocument;
} else if(doc.body){
//响应是html文档或纯文本
response = doc.body.innerHTML;

if(settings.responseType&& settings.responseType.toLowerCase()=='json'){
//如果文档以'application / javascript'或
//'text / javascript',然后浏览器将文本换行到< pre>
//标记并对内容执行html编码。在这种情况下,
//我们需要从文本节点的
// nodeValue属性中提取原始文本内容,以检索未翻译的内容。
//注意IE6只能理解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是一个xml文档
response = doc;
}

settings.onComplete.call(self,file,response);

//重新加载空白页,以便重新加载主页
//不重新提交帖子。另外,记住
//删除框架
toDeleteFlag = true;

//修复IE混合内容问题
iframe.src =javascript:'< html>< / html>';;
});
},
/ **
*上传文件包含在this._input中
* /
submit:function(){
var self = this, settings = this._settings;

if(!this._input || this._input.value ===''){
return;
}

var file = fileFromPath(this._input.value);

//用户返回false取消上传
if(false === settings.onSubmit.call(this,file,getExt(file))){
this._clearInput ();
return;
}

//发送请求
var iframe = this._createIframe();
var form = this._createForm(iframe);

//假设以下结构
// div - > input type ='file'
removeNode(this._input.parentNode);
removeClass(s​​elf._button,self._settings.hoverClass);
removeClass(s​​elf._button,self._settings.focusClass);

form.appendChild(this._input);

form.submit();

//请求集,清除
removeNode(form); form = null;
removeNode(this._input); this._input = null;

//准备就绪时获取iframe和fire onComplete事件的响应
this._getResponse(iframe,file);

//准备好下一个请求
this._createInput();
}
};


解决方案

检查代码是否在iframe中if not iframe in form.submit(),即

  document.iframename。 form.submit(); 


I created function to send email with a back link to my site, I'm using codeigniter framework

after user click that particular link (back link) on email, user redirects to my page which has an iframe.

i used that iframe to submit a form with file input, with out page refreshing.

When user coming through that link using gmail in IE9 browser the form.submit() function fails, in other browsers it works properly and other email(except gmail) too.

pleas help me to find solution

thank you.

update

actually I'm using the ajaxupload jquery library, it fails on the line form.submit(); at above scenario

     /* 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();
    }
};

解决方案

Check the the code is in iframe if not specify the iframe in form.submit(), i.e.

document.iframename.form.submit();

这篇关于为什么form.submit()失败IE9,当iframe中的表单和用户通过gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆