Solved

HTML code for automatic file download

Posted on 2013-11-06
11
351 Views
Last Modified: 2013-11-20
have a small piece of code with a hyperlink --- On click  --- downloads the file

<html>
<title>Company Name </title>
<body>
<a href="filepath\filename.ext”>Click here</a>
<body>
</html>

Objective to eliminate a click to download the file.
I wish the download automatically starts
Can anyone help please

Using javascript it is achievable using --- drawback is that it prompts a warning in IE saying Active X

Is there a way to open the link using html script itself.
0
Comment
Question by:MOQINFRA
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39629497
Not a good idea. normaly sites that try and automate downloads are downloading viruses or malware, at the very least something they dont want the user to have the choice of refusing.

you will loose more visitors doing this than you will please
0
 

Author Comment

by:MOQINFRA
ID: 39629508
It is an intranet site
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39629515
does your intranet have access to the web?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:QuinnDex
ID: 39629517
if it was my intranet and i found a way of allowing it, i would then want to stop it so files couldnt be downloaded to my network from other sites without at least user interaction.

couldnt you load the files from the server rather than through a web page
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39629558
Security restrictions in browsers prevent automatic downloads so people can't 'automatically' download viruses and malware on to your computer.  And just because it is an 'intranet' site does not mean that some of your users won't have bad files.
0
 

Author Comment

by:MOQINFRA
ID: 39629683
still if i need this , is there any modification we can make to the code for this functionality
0
 
LVL 7

Accepted Solution

by:
dimmergeek earned 500 total points
ID: 39633962
I have used this script on our Intranet to automatically download shortcuts to a person's desktop as well as their own partition on a network drive.  I give the user a confirmation box that confirms they want the file. We only use IE here, so this is an ActiveX solution.

// Make shortcuts on user's desktop
function makeLinks()
{
    var WshShell;
    var oShellLink;
    
    // AMRC Home Page
    WshShell = new ActiveXObject("WScript.Shell");
    strDesktop = WshShell.SpecialFolders("Desktop");
    oShellLink = WshShell.CreateShortcut(strDesktop + "\\AMRC Homepage.lnk");
    oShellLink.TargetPath = "file://G:\\AMRC\\AMRC_HOMEPAGE\\AMRC_HOMEPAGE.htm";
    oShellLink.WindowStyle = 1;
    oShellLink.Description = "AMRC Homepage";
    oShellLink.WorkingDirectory = strDesktop;
    oShellLink.IconLocation = "G://BR//AMRC.bmp";
    oShellLink.Save();
}

// Make shortcuts on user's F: drive
function makeFLinks()
{
    // Save shortcuts to F: drive
    var oShell = new ActiveXObject("Scripting.FileSystemObject");
    
    if (! oShell.FolderExists("F:\Shortcuts"))
    {
        oShell.CreateFolder("F:\Shortcuts");
    }
        
    // AMRC Home Page
    WshShell = new ActiveXObject("WScript.Shell");    
    oShellLink = WshShell.CreateShortcut("F:\\Shortcuts\\AMRC Homepage.lnk");
    oShellLink.TargetPath = "file://G:\\AMRC\\AMRC_HOMEPAGE\\AMRC_HOMEPAGE.htm";
    oShellLink.WindowStyle = 1;
    oShellLink.Description = "AMRC Homepage";
    oShellLink.WorkingDirectory = "F:\\Shortcuts\\";
    oShellLink.IconLocation = "G://BR//AMRC.bmp";
    oShellLink.Save();
}

Open in new window

0
 

Author Comment

by:MOQINFRA
ID: 39638780
Thanks
0
 
LVL 7

Expert Comment

by:dimmergeek
ID: 39639160
Was the code helpful?
0
 

Author Comment

by:MOQINFRA
ID: 39658470
I gave it to developer to check , he hasn't responded now.
0
 
LVL 7

Expert Comment

by:dimmergeek
ID: 39662524
Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question