messagebox - Javascript Alert Box (Stay on same page)? -


i'm creating download page in php, display alert box in javascript if download file not exist (when user clicks button corresponding product).

the problem is, once user hits ok on alert box, navigates away current page (that lists downloads). want stay on same page same content displayed.

full code:

<?php $product = $_get["p"]; $changefilename = "";  if ($product == 'product1') {     $realfilename = "originalfilename.exe";     $changefilename = "newfilenamehere.exe"; } elseif ($product == 'product2') {     $realfilename = "originalfilename.exe";     $changefilename = "newfilenamehere.exe"; } else {     echo '<script type="text/javascript">     alert("sorry, there no download available product! please contact support.");     </script>';     exit; }  $file = "downloads/".$realfilename; $fp = fopen($file, 'rb');  header("content-type: application/octet-stream"); header("content-disposition: attachment; filename=$changefilename"); header("content-length: " . filesize($file)); fpassthru($fp); ?> exit; 

you can open download page new window , ;

echo '<script type="text/javascript"> alert("sorry, there no download available product! please contact support."); window.close(); </script>'; exit; 

if download file not exist alert , close download page after first page.

or ajax download: download file using ajax request


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -