www.webdeveloper.com
Results 1 to 13 of 13

Thread: Appending parameters to exe downloads?

  1. #1
    Join Date
    Jun 2006
    Posts
    6

    Appending parameters to exe downloads?

    I'm a complete javascript novice, but I have pieced together some basic javascript that extracts the source parameters from a url when the page is loaded (using body onload=). For example:

    If the page is www.mysite.com/index.htm?source=test+one+two

    The parameters will be "source=test+one+two"

    For links on that web page, I use something like this to append the parameters when calling that link.

    <a href="index.htm" onClick="go('index.htm'); return false";>

    The "go" script is rather simple:

    function go(addr) {
    if (source==null){
    location.href=addr
    }
    else{
    location.href=addr+'?'+source;
    }
    }


    This all works great for htm links (web pages). However, if I try to use the same onClick link with an exe file it loses the exe information:

    <a href="test.exe" onClick="go('test.exe'); return false";>

    In other words, my browser pop's up as usual asking whether to open or save the file, but the .exe identifier is gone. Saving the file results in a document with no file extension.

    For now, I'm just using a basic link with .exe files <a href="test.exe">, but I would like to append the calling parameters to this URL too so I can track them in my access logs.

    Any help would be appreciated.

    Thanks,

    Anthony

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    Quote Originally Posted by awatson
    For links on that web page, I use something like this to append the parameters when calling that link.

    <a href="index.htm" onClick="go('index.htm'); return false";>

    The "go" script is rather simple:

    function go(addr) {
    if (source==null){
    location.href=addr
    }
    else{
    location.href=addr+'?'+source;
    }
    }
    First, let's simplify your code. Use this link:

    <a href="index.htm" onclick="return go(this)">

    and this function:
    Code:
    function go(link) {
      if (source) link.href += '?'+source;
      return true;
    }

  3. #3
    Join Date
    Jun 2006
    Posts
    6
    phpnovice,

    Thanks for the feedback, but your rewritten functions and links wouldn't work for me. The parameters do not get appended to the URL.

    Returned to my original code and everything works again, EXCEPT with links to exe files.

    Thanks,

    Anthony

  4. #4
    Join Date
    Dec 2004
    Posts
    8,637
    Quote Originally Posted by awatson
    ... your rewritten functions and links wouldn't work for me. The parameters do not get appended to the URL.
    Hmmm... Might this be a browser issue? That code works for me in IE and Mozilla.
    HTML Code:
    <html>
    <head>
    <script type="text/javascript">
    var source = "source=test";
    //
    function go(link) {
      if (source) link.href += '?'+source;
      return true;
    }
    </script>
    </head>
    
    <body>
    <p><a href="test.html" onclick="return go(this)">test.html</a></p>
    </body>
    </head>
    But, I suppose that is neither here nor there -- you are entitled to use whatever code suits (and works for) you.

  5. #5
    Join Date
    Jun 2006
    Posts
    6
    phpnovice,

    Strange, your full example worked fine for me. However, if I change the fixed source variable to the code I use to get the source from the URL, it no longer works (but it does work fine with my original code).

    function getSource(){
    source = document.URL.substring(is_input+1, document.URL.length);
    return source
    }

    Thanks,

    Anthony

  6. #6
    Join Date
    Dec 2004
    Posts
    8,637
    This:

    source = document.URL.substring(is_input+1, document.URL.length);

    can be changed to this:

    source = self.location.search.substr(1);

  7. #7
    Join Date
    Jun 2006
    Posts
    6
    phpnovice,

    Nice... Thanks!

    It still doesn't work with exe files, but it helps reduce the page sizes and should simplify maintenance as well.

    Anthony

  8. #8
    Join Date
    Dec 2004
    Posts
    8,637
    Alas! I cannot directly solve the problem with .exe files. Since they were never intended to accept a query/search string, this is probably why it causes a problem to have one. There is an alternative, but it would mean changing the whole method by which you are tracking this information.

  9. #9
    Join Date
    Jun 2006
    Posts
    6
    > I cannot directly solve the problem with .exe files

    Not a problem. I appreciate the input you have given already.

    > There is an alternative, but it would mean changing the whole
    > method by which you are tracking this information.

    What alternative are you thinking of?

    While we're talking javascript and exe files, do you know if there's a way to rename the exe file (or select alternate exe files) based on the URL parameters?

    i.e. www.mysite.com/page.htm?source=one

    would download file-one.exe

    www.mysite.com/page.htm?source=two

    would download file-two.exe

    Is this even possible with javascript? As I said, I'm a complete novice.

    Thanks,

    Anthony

  10. #10
    Join Date
    Dec 2004
    Posts
    8,637
    The alternative would solve the problem of .exe files and the renaming of files. Server-side code has the ability to tell the browser (not just IE) to open the download manager dialog ("Save As" dialog) and to specify the default file name to use. The file itself is sent as an HTTP Attachment -- this is what tells the browser to open the download manager dialog. As part of this attachment information, you can also specify the desired file name. Thus, the server-side code can keep track of the files it sends to the browser for download. A link like the following is how you could start this process:

    <a href="downloader.asp?file=myfile.exe">myfile.exe</a>

    The ASP document would know where to find the specified file and could download it with whatever alternative name it chose. This is also a good way to prevent your visitors from knowing where the file is found. This prevents them from bookmarking the location and easily retrieving the file again later. It forces them to go through your established process to obtain the file.

  11. #11
    Join Date
    Jun 2006
    Posts
    6
    Hmm... I hadn't thought about an ASP page just for downloads. It's probably a little too involved for my current needs, but I'll keep it in mind for the future.

    Thanks again for your help!

    Anthony

  12. #12
    Join Date
    Dec 2004
    Posts
    8,637
    Not just ASP -- in case you misunderstood. PHP can do it, too. And both only require about 25-50 lines of code (depending upon how you wish to store the tracking information.

  13. #13
    Join Date
    Feb 2006
    Location
    Where I live, people get shot. I need to move.
    Posts
    634
    I dont know if it helps, the issue with the .exe appending thingy...

    I used to have a web server set up to use a free cgi program, your request for the somefilename.exe?myAppendedText=someValue could be invoking a cgi program to find the value string ?myAppendedText=someValue and act on its value.

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