Easiest way to open a download window without navigating away from the page
7 years have passed and
I don't know whether it works for IE6 or not, but this prompts OpenFileDialog in FF and Chrome.
var file_path = 'host/path/file.ext';
var a = document.createElement('A');
a.href = file_path;
a.download = file_path.substr(file_path.lastIndexOf('/') + 1);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
How do you serve a file without leaving the page?
To avoid leaving the page (if you do this the page tries to close itself first, so that it's sure that you've saved everything, and you get warning messages if you haven't) or leaving blank tabs (which I don't like, nor the use of the depreciated target attribute) I've used an iframe, whose src attribute is changed in javascript.
This works everywhere except some versions of Opera, which I have considered an acceptable loss (I might fix that via the use of one of the other solutions plus browser detection later).
A download script and statcounter working together without opening a new page
What you want is not possible. (executing javascript on pdf download) Statcounter is an script and is executed by the browser by being included on the html. If you download a pdf file, you are not executing any js.
However, statcounter can see what links are pressed and therefore you can find which files were downloaded; as long your files are downloaded by using regular links on an html that has statcounter included. You don't need to do anything at all, they would be counted by default.
The idea Dachi gave, is to add an sql insertion to that php code of yours.
<?php
$dbh = new PDO("sqlite:/path/to/database.sdb");
//Put the insertion code here.
//Insert things like the IP, the login name, the time, etc.
header('Content-disposition: attachment; filename=brochure-company-details.pdf');
header('Content-type: pdf');
readfile('brochure-company-details.pdf');
That works too, and is a good choice if you are allowing downloads by not using regular links or not from an html that has statcounter.
Related Topics
How to Partition Input Field to Appear as Separate Input Fields on Screen
How to Wait for One Function to Finish Before Continuing
Check If Json Response Data Is Empty
How to Get Full Path of Selected File on Change of <Input Type='File'> Using Javascript, Jquery-Ajax
Regex to Find Json Values Without Quotes
Regex Pattern to Match At Least 1 Number and 1 Character in a String
React-Router Urls Don't Work When Refreshing or Writing Manually
Javascript Check If Values Exist in Array Json
Filter/Search from the Drop-Down List of Options Using Angular
How to Open a File/Browse Dialog Using JavaScript
Angular: Toggle Text of Button Based on Boolean Value in Model
How to Kill a Running Process on Windows from Nodejs
How to Make a Bot React to Its Own Message
Horizontal Scrollbar on Top and Bottom of Table
Disable Chrome Strict Mime Type Checking
How to Check If Input Field Is in Focus or Not
Disable/Hide Download Button in Iframe on Default Pdf Viewer