Forum Moderators: phranque
Most browser functions that deal with the context menu (i.e. Open, Copy Shortcut, Save As, etc.), can only be invoked through a right-click. You can use the Javascript command "document.execCommand('SaveAs',null,'yourmovie.mov')", but again... that will only save the webpage.
If you're into programming, you may be able to tweak the document.execCommand to see if there is a way to accomplish this.
The browser is identifying the MIME type and managing it accordingly. Even if you change the extension, most browsers will "sniff out" the file itself and try to manage it.
What you need to do is "tell" the browser it's something else from the server side and munge up the content-type header - that is, give it a content-type you KNOW it can't possibly understand. A sample in perl:
## Store the filename in a variable:
$filename = 'yourfile.mov';
## open file and store in a variable (e.g., in memory)
open (FILE,"$filename");
## Not usually, but SOMETIMES, on some servers, you
## have to specify binary mode when reading the file.
## binmode FILE;
while (<FILE>) { $file .= $_; }
close (FILE);
## Can't remember why this must be one more byte than length!
$size = length( $file)+1;
## tell the browser it's an unknown type.
## this can be anything that is NOT a known
## type, ex "Content-type: blabla/debla";
print "content-type: bad/type\n"; # ONE return
print "Content-Length: $size\n"; # ONE return
# "filename" populates save box.
print "Content-Disposition: attachment; filename=$filename\n\n"; ## TWO returns flushes the content-type header and ...
print " $file"; ## deliver the goods.
This works for binary or ASCII data; pdf's, media, images, anything. When you munge the content header the browser's only option is to offer the requested file as a download. The above can be emulated in any server-side language. But I don't know what you can do in JS, never tried. :-)
On all pdf files I always put "(right click to save to your hard drive)". I know that's not elegant, but you are also teaching them a new PC skill. That doesn't answer your automated question though. A self-extracting zip would work.
That wouldn't be too bad of an option. Is this somehwhat easy to create? I'll have to look into it more. Thanks.
Yes its very easy to create. All you have to do is right click on the file you want to compress and select "Create self-extracting..." (I don't have it installed on my work pc but it is labeled someting like that) and it will create the compressed file in the same location as the original. That should be all that is required.
These files are being treated as the spawn of satan in most browsers now and XP SP2 blocks the loading of .exe's by default and fires up a warning message about unsafe content.
This will turn off more people than a right-click instruction!
- spacerace -