iframe is opening in new tab after posting form da

2019-08-22 11:24发布

问题:

I am working on liferay portal where i have to done these tasks 1. on page load there is an I frame

<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 have to post a form data to that i frame
  2. I have successfully post the data but i frame is opening in new tab it making me a great trouble here is the code

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`