View Full Version : Download Button
garrettb
02-18-2003, 03:04 PM
I am building a page so that people can download new wallpaper for their computers. I want to have a download button that automatically takes them to the "save as" window. I have found some code to do this. I was thinking it would be better to have the button dynamically take the users to the correct file, depending on screen size. The code I am trying to use is below.
<body>
<script language="JavaScript">
function saveAsMe(file)
{
document.execCommand('SaveAs',true,file)
}
</script>
<script language="JavaScript">
if (screen.width==1024)
var file="Folders/allsteel_wallpaper1024.jpg"
else if (screen.width==800)
var file="Folders/allsteel_wallpaper800.jpg"
else if (screen.width==640)
var file="Folders/allsteel_wallpaper640.jpg"
</script>
<input type="button" value="Download" onclick="saveMeAs('file');">
</body>
I can get the page to come up without errors, but when the button is pushed it doesn't go anywhere. Any help would be appreciated.
beetle
02-18-2003, 03:32 PM
I thyink you want something more like this<body>
<script language="JavaScript">
function saveMeAs( wp )
{
var file = "Folders/" + wp;
switch( screen.height )
{
case 480: file += "640"; break;
case 600: file += "800"; break;
case 768: file += "1024"; break;
}
file += ".jpg";
document.execCommand('SaveAs',true,file)
}
</script>
<input type="button" value="Download" onclick="saveMeAs('allsteel_wallpaper');">
</body> It's better to check for screen height, because anybody with two monitors won't producs a width match that will satisfy one of your wallpaper sizes. Checking the height does :D
Oh, BTW, if you look at your old code, your function and function call are named different :p
The function could also be done this way, but has less room for error controlfunction saveMeAs( wp )
{
var res = {480: "640", 600: "800", 768: "1024"};
var file = "Folders/" + wp + res[screen.height] + ".jpg";
document.execCommand('SaveAs',true,file)
}
Borgtex
02-18-2003, 03:34 PM
Are you opening the image in a new window? I think that execCommand('SaveAs') only saves the contents of a page, not an specific object.
also, remove the quotes when you call the saveMeAs function; files is a variable, not a string:
saveMeAs(file)
garrettb
02-18-2003, 03:47 PM
Thanks for the quick response beetle. I tried it out, but when the button is clicked it still doesn't do anything. Any other suggestions?
beetle
02-18-2003, 03:50 PM
Not sure, I never really used execCommand(). Read up on 'SaveAs' and 'execCommand' here (http://msdn.microsoft.com/workshop/author/dhtml/reference/constants/saveas.asp)
garrettb
02-18-2003, 03:50 PM
Borg, I am trying to get the save as window to appear like it does when you right click on a link and choose "save target as..." I know you can get this to happen by zipping the file, but I don't want to go that route. Do you know any other way to get the save as window to appear without right clicking?
Tails
02-18-2003, 08:09 PM
I'm intested in learning about what
document.execCommand('SaveAs',true,file) and similar things can do. I have RAR files that I would rather post on my site than ZIP but the Mimetype is not recognized by the server and the filetype does not offer a "save as" box, but instead tells the client to open in notepad. I don't think this has anything to do with the client's mimetypes, but I want the download box to be there indefinately. Do I have any options that do not require server-side techiniques?
Borgtex
02-19-2003, 11:50 AM
try to open the image in a iframe:
http://www.faqts.com/knowledge_base/view.phtml/aid/16516/fid/53
or open a new window with the image:
http://www.faqts.com/knowledge_base/view.phtml/aid/2009/fid/122
I think that it can't be done the way you want :(
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.