将表单数据发布到iframe后,iframe在新选项卡中打开

时间:2017-02-09 07:25:35

标签: javascript jquery html html5 iframe

我在liferay门户网站上工作,我必须完成这些任务 1.在页面加载时有一个I帧

<iframe id="sstIframe" name="sstIframe" border="0" frameborder="0" hspace="0" scrolling="no" vspace="0" width="100%" height="400" src="<% if(bankfastUrl.contains("-login") || bankfastUrl.contains("rcasPId=")){%><%= bankfastUrl %><%}%>"></iframe>

  1. 我必须将表单数据发布到i frame
  2. 我已经成功发布了数据,但我的框架在新标签中打开,这让我很麻烦,这里是代码
  3. function setupSstIframeWithform(){
            var object = this;
            var iframeUrl = $('#sstIframe').attr('src');
            if($('#sstIframe').get(0)){
            var object = this;
            object.form = $('<form action="'+iframeUrl+'" method="post" style="display:none;" target="sstIframe" id="formForIframe" name="formForIframe" ></form>');
    
              var requestParams = sessionStorage.getItem("sstParam");
              if(requestParams){
                var sstParams = JSON.parse(requestParams);
                if(sstParams){
                   $.each(sstParams, function(value,key){
                     if(value){
                      $("<input type='hidden' />")
                      .attr("name", key)
                      .attr("value", value)
                      .appendTo(object.form);
                    }
                  })
                }
              };
              var form = document.getElementById('myform');
              object.form.submit = function() {
                  form.target = '_self';
              };
              $( "body" ).append(object.form);
               
              object.form.submit();
              object.form.remove();
          }
      }
        setupSstIframeWithform();`enter code here`

0 个答案:

没有答案