www.webdeveloper.com
Results 1 to 3 of 3

Thread: Help With JavaScript Automatic Download Injection

  1. #1
    Join Date
    May 2014
    Posts
    1

    Question Help With JavaScript Automatic Download Injection

    Hello,

    I have been asked if I could make a small piece of code that would download a specific file off a website automatically, however as I have little to no background in web dev I was wondering if someone could please help? I trowled through google a bit and didn't find anything relating specifically to what I need to do so here I am.

    Basically I have been asked to download the file on this website, when you press the "Export" button in the right hand side and then the "Export" button on the form that appears which then initates a download of the file "PracticeProfiles.xls".

    I got the first part, by issueing "javascript:showExport()", however am now a little lost from there..

    I had a look at the wesite and this file seems to be generated as oposed to having a hard link somewhere to it on the server (I may be wrong).

    Can anyone suggest how I would achieve this using JavaScript Injections please?

    Many Thanks

    DoctorZeus

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,343
    After poking around the JavaScript, I can see that they are using a mix of JavaScript and JQuery to do some of the leg work.

    My suggestion is to look at the JavaScripting to find the polling URL that causes the file generation and try a server-side cURL poll or similar to pull the data off the server.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    May 2014
    Posts
    842
    Cheap trick -- make an anchor that links to the file in javascript... then call it's click() method.

    Code:
    var a = d.body.appendChild(d.createElement('a'));
    a.href="file.txt";
    a.click();
    You have to append it to body or Firefox and Chrome ignores it, though "real" Opera and IE will obey it without the appendChild... Since it has no text in it, the appendChild is usually safe... though you might want to detect if you already have one so if there are multiple downloads you don't fill up the DOM with empty anchors.
    Last edited by deathshadow; 06-01-2014 at 10:05 AM.
    Java is to JavaScript as Ham is to Hamburger.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles