除非调整窗口大小,否则iFrame无法在Chrome中加载

时间:2015-04-22 16:30:20

标签: javascript jquery html iframe

我的网页如下,左侧有Invoice numbers,当用户点击它时,其详细信息会加载到iframe(id='invoiceFrame')中,这在IE中可以正常使用但在Chrome中却没有iframe加载,除非窗口调整大小

Google Chrome Version 42.0.2311.90 (Official Build) m (32-bit)

<script type="text/javascript">
   function getUrlParameter(URL, param){
    var paramTokens = URL.slice(URL.indexOf('?') + 1).split('&');
    for (var i = 0; i < paramTokens.length; i++) {
        var urlParams = paramTokens[i].split('=');
        if (urlParams[0].endsWith(param)) {
            return urlParams[1];
        }
    }
  } 
String.prototype.endsWith = function(pattern) {
    var d = this.length - pattern.length;
    return d >= 0 && this.lastIndexOf(pattern) === d;
};

 function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
    jQuery(document).ready(function () {
    jQuery("#mainFrame").hide();
   jQuery('#invoiceList tr:not(:first-child)').click(function(e){
    jQuery(".message").hide();
    e.preventDefault();
    var invoiceNumber =  jQuery(this).find("td").eq(0).text();
    var url = window.location.href;
   var lipId = getUrlParameter(url, 'lipId') 
  var invURL = '/CP/Invoice/InvoiceLineErrors.do?lipId='+lipId+'&invNum='+invoiceNumber;
   console.log('invoiceNumber '+invURL);
  jQuery("#mainFrame").show();
 document.getElementById("mainFrame").src =invURL;

});
   });
  </script>
       <style>
    h2.message{text-align: center; color: #FDFDFD; font-size: 1.1em; background: #708fc3; }  
    #invoiceList{ float: left; width: 15%; overflow-x:auto; }
    #invoiceFrame{float: right; width: 83.5%;   margin-bottom: 0em !important; }

        td error { color: red; font-size: 100%;} 
       tr.errortrue { color: #c33; font-size: 100%; font-weight: bold;} 
        table#lines th { background-color : grey;  color: white; width:100%}
       table {margin-bottom: 2em; border-bottom: 2px solid #ebebeb; empty-cells: show; border-collapse: collapse; }
       table#lines td { text-align: center; width:100%}

    iframe { float: left; width: 100%;  height =300px;
        }
       </style>
    </head>
    <body id='foo'>
<div class="ui-widget">
<center><h1> Invoice Error Details For ePacket P00000080235</h1></center>
  <div class="panel ui-widget-content" id="invoiceList">
 <h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; font-size: 1.1em; "><span>Invoices</span></h2>
<table cellspacing='0' id='header' class="ui-widget">
   <tr>
        <th>Invoice Number</th>
         <th>Invoice Total</th>
  </tr>
  <tr class = 'errortrue'>
      <td>2015.04.08.001</td>
      <td>59.97</td>
  </tr>
</table> 
</div>
<!-- <div class='panel ui-widget-content' id="invoiceDetails">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; "><span>Select the Invoice Number on the left to view the error details</span></h2>-->
<h2 class='message'><span>Select the Invoice Number on the left to view the error details</span></h2>
<div class='panel ui-widget-content' id="invoiceFrame"><iframe src="" id="mainFrame" name="mainFrame" scrolling="no"  class='panel ui-widget-content' onload='javascript:resizeIframe(this);'></iframe>
    </div>

</div>
    </body>

以下是iframe的内容

<script type="text/javascript">
jQuery('table#lines tr').each(function(){
  if (jQuery(this).html() == '') {
    jQuery(this).hide();
  }
});
  </script>
       <style>
       #invoice {padding: 0;}
       #invoiceErrors {overflow-x: auto;  overflow-y: auto;}
       tbody td{ border-top: 2px solid #efefef; border-bottom: 0px !important ;}
       td.error { text-align: left; color: #c33; font-size: 100%; background-image: none !important; padding-left : 0; border-bottom: 2px solid #0891F4;   white-space: nowrap;} 
       tr.errortrue { color: #c33; font-size: 100%; font-weight: bold;   white-space: nowrap;} 

       table {empty-cells: show; border-collapse: collapse; }
       table#lines td { text-align: left;}

       </style>
    </head>
<body id='invoice'>
 <div id="invoiceErrors">
  <div class='panel ui-widget-content' id="invoiceHeaders">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; font-family: Tahoma,Arial,sans-serif; font-size: 1.2em;"><span>Header Details</span></h2>
    <table class="ui-widget" id="headers">
                   <tr>
                        <th>Invoice Number</th>
                         <th>Matter Number</th>
                        <th>Invoice Total</th>
                        <th>Invoice Tax Total</th>
                        <th>Invoice Net Total</th>
                  </tr>

                     <tr class='errortrue'>
                        <td>2015.04.08.001</td>
                         <td>MAT-2</td>
                        <td>59.97</td>
                        <td>59.97</td>
                        <td>59.97</td>
                  </tr>
<tr ><td class = 'error'  style="padding-bottom: 4%;">

              Line : 1 Invoice tax total does not foot Reported = (0.0) Calculated = (1.0)<br/>

              Line : 1 Invoice Taxable Amount does not foot Reported = (59.97) Calculated = (58.97)<br/>

</td></tr>
  </table> 
</div>
<div class='panel ui-widget-content' id="invoiceLines">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; font-family: Tahoma,Arial,sans-serif; font-size: 1.2em;"><span>Invoice Line Items</span></h2>

 <table class="ui-widget" id="lines">
<tr>
<th>Line Item Number</th>
<th>Line Item Date</th>
<th>Unit Cost</th>
<th>Number of Units</th>
<th>Line Item Total</th>
</tr>

<tr class='errortrue'>
<td>1</td>
<td>20150402</td>
<td>19.99</td>
<td>3</td>
<td>59.97</td>
</tr>
<tr>
<td colspan="9" class='error' style="padding-bottom: 6%;">       
      Line : 1 MATH ERROR: ((19.99*3.0) - (0.0)) * (1.0) != 1.0 variance = 58.97<br/>
      Line : 1 MATH ERROR: (19.99*3.0) - (0.0) + (1.0) != 59.97 variance = 1.0<br/>
</td>
</tr>

</table>

</div>
 </div>
</body>

有人可以帮我解决iframe问题吗?

2 个答案:

答案 0 :(得分:2)

尝试向iframe添加位置

iframe { float: left; width: 100%; height :300px; position:relative}

答案 1 :(得分:0)

我使用此替代方法使其工作:

var iframe = $('<iframe>', {
  src: url,
  frameborder: 0,
  load: function () {
    // fixes Chrome not painting iframe until window resizes
    // https://bugs.chromium.org/p/chromium/issues/detail?id=481922
    iframe.contents().find('body').hide(0).show(0);
    // end repaint fix
  }
});