
zottona wrote:How to do enable downloading in javascript? What is the javascript code so that when a button is pressed the file downloads? Thanx.

Vinoth wrote:Hi zottona,
We can't not download a file using javascript. We can download file by setting header at server side.zottona wrote:How to do enable downloading in javascript? What is the javascript code so that when a button is pressed the file downloads? Thanx.
<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)
}
Users browsing this forum: No registered users and 1 guest