Solved

HTML code for automatic file download

Posted on 2013-11-06
11
348 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

919 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

18 Experts available now in Live!

Get 1:1 Help Now