Reputation: 2599
I have a link which launches a new html page in a new tab with simple jquery, like _target=blank
, no issue.
Expected:
Current unexpected behavior:
Shortly, I want to keep the page open, while prompting a Save as dialog.
Using Content-Disposition
attachment seems to have no chance to keep the page open.
I didn't do any exit();
either, but the page is never showed, except for the dialog.
Thanks
Upvotes: 2
Views: 287
Reputation: 1253
send refresh headers
header("Refresh: 5; url=http://www.example.com?download=1");
instead of the need to modify your template to add meta tags
Upvotes: 0
Reputation: 14834
Try pulling your page initially as a normal page, and use a meta refresh to redirect to the same url with a parameter telling your PHP to serve the page again as a download.
Example:
<?php
$isDownload = isset( $_GET['download'] );
if( $isDownload ) {
header( 'Content-disposition: attachment' );
}
?>
<html>
<head>
<?php if( !$isDownload ) { ?>
<meta http-equiv="refresh" content="0;<?=$_SERVER['REQUEST_URI']?>?download" />
<?php } ?>
...
Upvotes: 4
Reputation: 1607
Insert a meta refresh tag into the page that you are currently serving in the popup. This meta refresh should point to the file you want to be downloaded:
popup.php:
<head>
...
<meta http-equiv="refresh" content="10;URL='http://www.example.com/downloads/file.ext'" />
...
</head>
This will show popup.php in the new window, and after 10 seconds a save dialog will show prompting the user to download the file file.ext
Upvotes: 1
Reputation: 7
not sure if this is a good answer or not.. but perhaps.. open the page that displays the save as dialog box & try some document.location.href = "abspathtofile"; in js.. though i'm not sure if this is what you're looking for..
Upvotes: 1