473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Prompting user to save a Javascript created text to a file

Hi,

I'd like to be able to prompt the user to save text that a script has
created to a file.

The idea is that the script would create a text string, the "Save As"
dialog would be triggered and then the user could choose to save the
text that was created somewhere on their local filesystem. This has
none of the security concerns of Javascript being able to write to the
local filesystem but still allows me to customize data to the user.

With Firefox, doing the following almost works, but I haven't figured
out a way to suggest a default filename (Firefox, uses what appears to
be a random string). IE croaks on it.

window.location = "data:plain/text,Test";

This prompts me to save the file and when I do the string "Test" is
contained within the file.

Does anyone know how to do this the right way? Hopefully, also in a
cross-browser way?

Thanks!
Jeff

Jan 17 '07 #1
4 3602
Ivo
"Jeff" wrote
I'd like to be able to prompt the user to save text that a script has
created to a file.
With Firefox, doing the following almost works, but I haven't figured
out a way to suggest a default filename (Firefox, uses what appears to
be a random string). IE croaks on it.

window.location = "data:plain/text,Test";

This prompts me to save the file and when I do the string "Test" is
contained within the file.
Interesting, I 'll have to try that out.
For IE, see
http://4umi.com/web/javascript/filewrite.htm
HTH
Ivo
Jan 17 '07 #2
Jeff wrote:
>With Firefox, doing the following almost works, but I haven't figured
out a way to suggest a default filename (Firefox, uses what appears to
be a random string). IE croaks on it.

window.location = "data:plain/text,Test";

This prompts me to save the file and when I do the string "Test" is
contained within the file.
You made me wonder about this. I figured that the plain/text was
actually a mangled MIME content type. Indeed, replacing it with
"text/plain" makes the browser show it; replacing it with "text/html"
makes the browser show the data as HTML.

I went Googling, and found a page in Wikipedia:

Data: URI scheme
<http://en.wikipedia.org/wiki/Data:_URI_scheme>

I fine starting point for any further queries. Like workarounds for MSIE
that according to the article still doesn't handle it.
--
Bart.
Jan 17 '07 #3
VK
Jeff wrote:
With Firefox, doing the following almost works, but I haven't figured
out a way to suggest a default filename (Firefox, uses what appears to
be a random string). IE croaks on it.

window.location = "data:plain/text,Test";

This prompts me to save the file and when I do the string "Test" is
contained within the file.
You've made me worried for a sec by your discover:
<https://bugzilla.mozilla.org/show_bug.cgi?id=367231>

Sorry, nothing personal, just a quick security check. As you may see it
is not a bug but an enhancement request now.

Just in case I quote the clarification about the file name:
"since it wasn't loaded from a particular path from which we could take
a file name, and because it's not an HTML document where we could use
the <title>, we pick a unique temporary name.
Because it's confusing you could make the case for an enhancement
request that we should prompt the user for a filename when we don't
have one rather than pick something random."

Jan 17 '07 #4
VK

VK wrote:
You've made me worried for a sec by your discover:
<https://bugzilla.mozilla.org/show_bug.cgi?id=367231>

Sorry, nothing personal, just a quick security check.
To make it all clear: I pointed to the exact founder not for some
"responsibility shift" or so. But in case if it was confirmed as a
direct or potential security risk you would be the one entitled for the
US $500 cash bonus from Mozilla.

Jan 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: George Hester | last post by:
My site is all one color basically. But I'd like to give the user the ability to make the site a color of their choice. I have it set up so that they can choose the color of the logon page and save...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
5
by: Patrick F | last post by:
I got a link to my .aspx page, when the link is pressed i want the user to be able to download what the .aspx sends to it. Inside my .aspx page i have a string called strPage, i want that strPage...
3
by: kim | last post by:
GOOD morning, I try to open xx.vbs in <href="./xx.vbs"></hef> but it pop up the file download mesage. How can i disabled it? I try another solution like this : set ws =...
5
by: Phillip N Rounds | last post by:
I have a webform ( ASP.NET 1.1, CodeBehinde = C#). The user selects an address item from a dropdown list box. The details of the address then populate appropriate text boxes. Each textbox has an...
7
by: mattmerc | last post by:
Hi all, We have all seen lot of method for exporting datagrids to Excel. I have a slightly different need. I think it should be easy to accomplish but I am not sure how. I would like when a user...
11
by: uoL | last post by:
Hello, I'd like to know how to prompt two values with prompt(); function. I need to get things like 'pass' and 'user, 'article' and 'value', etc ... in a document and I dont want to make a...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
1
by: Sudarhan | last post by:
Hello frnds I have created a webbased form using asp and javascript .. while submitting the form i am validating the fields in the form .it validates the field and returns alert message. but when...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.