Solved

HTML code for automatic file download

Posted on 2013-11-06
11
347 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
Comment Utility
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
Comment Utility
It is an intranet site
0
 
LVL 9

Expert Comment

by:QuinnDex
Comment Utility
does your intranet have access to the web?
0
 
LVL 9

Expert Comment

by:QuinnDex
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:MOQINFRA
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0
 
LVL 7

Expert Comment

by:dimmergeek
Comment Utility
Was the code helpful?
0
 

Author Comment

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

Expert Comment

by:dimmergeek
Comment Utility
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now