How to capture file save as cancel respond
<p>I followed this post <a href="http://www.the-art-of-web.com/php/dataexport/" rel="nofollow">http://www.the-art-of-web.com/php/dataexport/</a> and successfully create an export to csv file from DB, base on user current search view. But to prevent hit to db while export is happening so I disable the export unless there is change within the view or user query.  The issue I face with is when user hit on export a file save as confirm dialog pop up and if user changed her mind click on cancel.  The export button remain disable.  The only way for user to get back is to change query and come back again.  </p>

<p>My question is there anyway I could capture the cancel click respond on file save as confirm dialog.</p>

<p>Thanks</p>

<p>The code is very similar to <a href="http://www.the-art-of-web.com/php/dataexport/" rel="nofollow">http://www.the-art-of-web.com/php/dataexport/</a>  Where as the view would be a grid with bunch of customer information from given date range.  If user like the view they choose.  They would click on export button.  </p>

<p>sample code
export.php</p>

<pre><code>function exportCSV(){
  document.getElementById("exportCSV").src = "test1.php";
  document.getElementById("exportBtn").disabled = true;
}

function performSearch(){
  //perform search get result and display
  //if resultset length &gt; 0
  document.getElementById("exportBtn").disabled = false;
}
</code></pre>

<p>Grid display right here
 &lt;button id="search" onclick="performSearch()">Search <br>
 &lt;button id="exportBtn" onclick="exportCSV()"> Export <br>
 &lt;iframe id="exportCSV" style="display:none"/><br></p>

<p>test1.php</p>

<p>$data = array(<br>
       array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25),<br>
       array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18),<br>
       array("firstname" => "James", "lastname" => "Brown", "age" => 31),<br>
       array("firstname" => "Patricia", "lastname" => "Williams", "age" => 7),<br>
       array("firstname" => "Michael", "lastname" => "Davis", "age" => 43),<br>
       array("firstname" => "Sarah", "lastname" => "Miller", "age" => 24),<br>
       array("firstname" => "Patrick", "lastname" => "Miller", "age" => 27)<br>
     );</p>

<p># filename for download
 $filename = "website_data.xls";</p>

<p>header("Content-Disposition: application/octet-stream; filename=\"$filename\"");<br>
 header("Content-Type: application/vnd.ms-excel");</p>

<p>$flag = false;<br>
 foreach($data as $row) {<br>
   if(!$flag) {<br>
     # display field/column names as first row<br>
     echo implode("\t", array_keys($row)) . "\n";<br>
     $flag = true;<br>
   }<br>
   array_walk($row, 'cleanData');<br>
   echo implode("\t", array_values($row)) . "\n";<br>
 }<br>
 exit;    <br></p>

<pre><code> function cleanData(&amp;$str)
 {
   $str = preg_replace("/\t/", "\\t", $str);
   $str = preg_replace("/\r?\n/", "\\n", $str);
   if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
 }     
</code></pre>
