Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent file download

Status
Not open for further replies.

postyr

Programmer
Feb 14, 2009
6
AU
I have a link to open an Excel file in a new window, which works fine unless the user does not have Excel installed.

If they don’t, the window doesn’t open, and they are given the option to choose a program to open it with, or to save (download) the file.

As it is a sensitive “members only” type of file, I do not want any user to be able to download it

Is there a way to test the window.open() function so that if the window doesn’t open, I can display a message and exit the script before the “Download” box is displayed.

Thanks in advance,
postyr

 
You can do something like this to prepare for window.open(). In any case, it is just a compromise between functionality and annoyance. Even if excel is installed, it is still not guaranteed the client integrate it with the browser functionality, that means, the download popup may still be the client's preferred setting that you can't do thing about.
[tt]
if (window.ActiveXObject) {
try {
if (new ActiveXObject("Excel.Application")) {
window.open("[blue]your-url[/blue]");
//etc etc other followup actions
}
} catch (e) {
//alert("err: "+e.description);
//etc etc in case excel is not installed
}
} else {
//alert("ActiveXObject not supported");
//they are not using ie, what to do?
}[/tt]
 
Thanks tsuji for your reply and information.

I'll give it a try.

 
tsuji, tried your suggestion and it works brilliantly (in IE anyway). Thanks again.

Pity it won't work in other browsers.

I may have a look at some PHP to find something simlar. But in the meantime, I will use your code with much appreciation.

 
As it is a sensitive "members only" type of file, I do not want any user to be able to download it

Why be so restrictive? Once the file is opened in Excel, a simple "Save As" would be enough to take a copy of the file, so why stop people choosing to download it for later viewing it they can do this anyway?

Dan


Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Dan,

The file is all handled by code. All menus, shortcut menus and shortcut keys are deleted or disabled upon openeing (they are reset uopon close).

The file is saved to a specific location within the code upon clicking a certain button. If changes are made, and the file is closed without saving, the user is prompted to save (which doesn't work anyway, as it is server based), but can't "Save As".

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top