Results 1 to 4 of 4

Thread: How to enable Javascript Force Download

  1. #1
    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.

  2. #2
    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

  3. #3
    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]);

  4. #4
    Join Date
    May 2008
    Posts
    2,792

    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>

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,020,760.01160 seconds with 17 queries