how can I using javascript to save javascript value to a file

I would like write a page using javascript . The user can load this page and then offline do some input. Then click one button to save the changed javascript value to a file on local disk. Any one can give me a solution?
TimSenior PHP DeveloperAsked:
Who is Participating?
 
cevomanCommented:
You could do the below code and then have a button which calls a function and calls the below function with the appropriate data
function writeJSValue(newData)
	{
		var newWindow = window.open("",newWindow','width=1,height=1');
		newWindow.document.write(newData);
		newWindow.document.write("<script language=\"javascript\">document.execCommand('SaveAs')</script>");
		newWindow.document.close();
		newWindow.close();
	}

Open in new window

0
 
cevomanCommented:
Hi there,

For security reasons aside from a cookie Javascript does not allow a user to read or write local or server files
there is only really one way of allowing this and that's if the user has a activex control which is written for

but as standard it can't be done otherwise there would be more security issues on the web than there is already

Kind regards
James
0
 
TimSenior PHP DeveloperAuthor Commented:
How about using document.execCommand('SaveAs'). I would like the user can save the information  as a file offine, later he can update this file.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
cevomanCommented:
The only issue is that document.execCommand('SaveAs'...) is only a IE implentation and if the user clicks file --> save as... or CTRL + S that will also work

I'm not aware there is anyway to do this in firefox as it could be a potential security risk on the clients side.

Kind regards
James
0
 
TimSenior PHP DeveloperAuthor Commented:
Just IE is ok. The point is I do not want save whole page, just want save one javascript value as a txt file. Any solution?
Thanks
0
 
TimSenior PHP DeveloperAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.