Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-05-2009
Member
 
Join Date: May 2009
Posts: 60
How to enable Javascript Force Download

I am trying to save a file to a specific location from a web page by configuring it to save to particular location directly. I want to save the file by enabling javascript force download. How can i make javascript to force download a file. I know that we can save a file by using save as option. I want to know the step how to enable javascript to force download a file in specific location.
Reply With Quote
  #2  
Old 18-05-2009
Member
 
Join Date: Apr 2008
Posts: 2,277
Re: How to enable Javascript Force Download

I believe that that the below code will help and it will solve your problem of download.

HTML Code:
<body>
<script>
function downloadme(x){
myTempWindow = window.open(x,'','left=10000,screenX=10000');
myTempWindow.document.execCommand('SaveAs','null','download.pdf');
myTempWindow.close();
}
</script>

<a href=javascript:downloadme('/test.pdf');>Download this pdf</a>
</body>
Bye
Reply With Quote
  #3  
Old 18-05-2009
Member
 
Join Date: Apr 2008
Posts: 2,276
Re: How to enable Javascript Force Download

To force download a audio you can use the following script.
in .htaccess file (if running apache)
HTML Code:
<Files mp3>
ForceType application/x-httpd-php
</Files>
HTML Code:
mp3 (no extension)
<?php
$uri = explode("/",$_SERVER['PATH_INFO']);
$path = "/path/to/mp3/files/"; //path without any filenames!!! Must have trailing backslash
header("Content-Description: File Transfer");

header("Content-Type: application/force-download");

header("Content-Disposition: attachment; filename=".basename($path.$uri[1]));

@readfile($path.$uri[1]);
Reply With Quote
  #4  
Old 18-05-2009
Member
 
Join Date: May 2008
Posts: 2,786
Re: How to enable Javascript Force Download

Use the Piwik tool. It is quiet a common way to tag JavaScript. You can customize your tags. By default Piwik uses the URL of the current page as the ?action? name in the Piwik interface.
After downloading the tool give the following tags :
Force a click on a link to be recorded as a download in Piwik

If you want Piwik to consider a given link as a download, you can add the ?piwik_download? css class to the link:

HTML Code:
<a href='last.php' class=?piwik_download?>Link I want to track as a download</a>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to enable Javascript Force Download"
Thread Thread Starter Forum Replies Last Post
How to enable javascript in IE8 roshan45 Technology & Internet 4 26-10-2009 08:23 PM
Enable Android Javascript Mind It Software Development 2 21-09-2009 03:07 PM
How to enable Javascript in PHP Rebella Software Development 3 12-05-2009 11:52 PM
i need to enable javascript ben4147 Windows Update 10 06-05-2008 09:15 PM
Where is in IE 7 enable/disable javascript? Jack Vista Help 3 06-04-2007 06:14 AM


All times are GMT +5.5. The time now is 12:22 AM.