2013-05-03 63 views
1

我有2個表單提交一次提交點擊,下載2個文件。JavaScript提交2個表格不能在鉻工作

這是在Firefox中下載2個文件,但在Chrome中只下載1個文件。

我已根據請求編輯並插入完整的代碼。

全碼:

   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <title>EXPORT INVOICE </title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

    <SCRIPT LANGUAGE="JavaScript"> 
     function runscript() 
     { 
     document.f1.submit(); 
     document.f2.submit(); 
     } 
    </script> 
    </head> 

    <body> 

    <form name="f1" method="post" action="export-tst-with-header.php" target="_blank"> 

    <table width="810" height="140" border="0" cellpadding="5" cellspacing="0" class="uniq" align="center"> 
     <tr class="uniq"> 
     <td width="363" valign="middle"> 
     <br> 
     <span class="sty2">Enter to export From Invoice No.:</span>  <input type="text" size='10' maxlength='10' name="finv" onblur="showfrom(this.value);"> 
     &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
     <span class="sty2">To Invoice No:</span>&nbsp; <input type="text" size='10' maxlength='10' name="tinv" onblur="showto(this.value);"> 
     </td> 
     </tr> 
     <tr class="uniq"> 
     <td width="363" valign="top"><div align="center"><br> 
      <br> 
      </form> 

      <form name="f2" method="post" action="export-tst-with-header2.php" target="_blank"> 
      </form> 

      <input type="button" value="Export" onClick="runscript();" /> 



    &nbsp;&nbsp; 
    &nbsp;&nbsp; 
      <a href='index.htm' target='_parent'><input name="close" type="button" value="Close !"></a> 
     </div></td> 
     </tr> 
    </table> 

    <br> 
    </body> 
    </html> 
+1

您的HTML存在驗證問題,您在表格標籤前打開第一個表格標籤,但在表格內關閉它。你可能想要解決這個問題。 – Turnerj 2013-05-03 10:24:19

+0

@sridhir:請發佈完整的html和javascript代碼 – 2013-05-03 10:27:38

+0

我剛剛發佈了代碼的一部分,我有一個問題。 – 2013-05-03 10:30:32

回答

1

編輯:下面是測試我跑,我在那裏清理了大量的HTML和JS你的問題。我發現這個解決方案實際上會在Chrome中同時訪問這兩個網址。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<title>EXPORT INVOICE </title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 

<script type="text/javascript"> 
    function runscript() { 
     document.forms.f1.submit(); 
     window.setTimeout(function() { 
      document.forms.f2.submit(); 
     }, 500); 
    } 
</script> 
</head> 
<body> 
    <table width="810" height="140" border="0" cellpadding="5" cellspacing="0" class="uniq" align="center"> 
     <tr class="uniq"> 
      <td width="363" valign="middle"> 
       <form name="f1" method="post" action="export-tst-with-header.php" target="_blank"> 
        <br /> 
        <span class="sty2">Enter to export From Invoice No.:</span> 
        <input type="text" size='10' maxlength='10' name="finv" onblur="showfrom(this.value);" /> 
        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        <span class="sty2">To Invoice No:</span>&nbsp; 
        <input type="text" size='10' maxlength='10' name="tinv" onblur="showto(this.value);" /> 
       </form> 
      </td> 
     </tr> 
     <tr class="uniq"> 
      <td width="363" valign="top"> 
       <div align="center"> 
       <br /> 
       <br /> 
       <form name="f2" method="post" action="export-tst-with-header2.php" target="_blank"> 
       </form> 
       <input type="button" value="Export" onClick="runscript();" /> 
       &nbsp;&nbsp; 
       &nbsp;&nbsp; 
       <a href='index.htm' target='_parent'><input name="close" type="button" value="Close !"></a> 
       </div> 
      </td> 
     </tr> 
    </table> 
    <br /> 
</body> 
</html> 
+0

即使在更改javascript後也沒有區別。 – 2013-05-03 10:29:19

+0

這不提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 – 2013-05-03 10:43:11

+0

@LyubenTodorov,感謝您對網站規則的澄清,但實際上,這是對答案的嘗試......即使它沒有解決他的問題。事實上,document.forms集合在所有瀏覽器的JS中都是通用的,而在文檔級別訪問元素則不是。 – 2013-05-03 10:44:55