javascript

Get help on javascript coding. discuss javascript, issues, methods and solution involving javascript.

javascript

New postby zottona on Wed Oct 21, 2009 4:47 pm

How to do enable downloading in javascript? What is the javascript code so that when a button is pressed the file downloads? Thanx.
zottona
Newbee
Newbee
 
Posts: 1
Joined: Thu Oct 15, 2009 10:33 am


Re: javascript

New postby Vinoth on Wed Oct 21, 2009 5:13 pm

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.
User avatar
Vinoth
Enthusiast
Enthusiast
 
Posts: 389
Joined: Sat Sep 06, 2008 1:31 pm
Location: Follow me on Twitter @t_vinoth

Re: javascript

New postby xyeshu on Fri Nov 06, 2009 7:40 pm

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.


Just try this for download button in javascript.


Code: Select all
<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)
}
User avatar
xyeshu
Newbee
Newbee
 
Posts: 15
Joined: Sat Oct 10, 2009 5:23 pm


Return to Javascript

Who is online

Users browsing this forum: No registered users and 1 guest