By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

Problem When Using execCommand("SaveAs",false,".txt")

P: 16
Hi All!

I am using Javascript to export some content in a popup (in this case, just 5 simple words) to a text file. This works fine and the user can save the text file.

Upon opening the file, it appears to be just a basic text file, however, i encounterd a problem importing this into flash (thats another story!). The text file needs to consist of just a line of text for the import (ie. word1=hello&word2=world), this is how it appears in notepad. But, when opened in a hex editor, it shows that there are stops inbetween every letter/number! (w.o.r.d.1.=.h.e.l.l.o.&.w.o.r.d.2.=.w.o.r.l.d) These are represented as 00 in hex...

I think this may be a problem with my javascript as i am fairly new to the language.

Any help would be greatly appreciated!

Cheers.

Gav
Sep 25 '07 #1
Share this Question
Share on Google+
4 Replies


acoder
Expert Mod 15k+
P: 16,027
Post the code you have used.
Sep 25 '07 #2

P: 16
Heres the Javascript code im using

Expand|Select|Wrap|Line Numbers
  1. <script language=JavaScript>
  2.  
  3. function test() {
  4. output = window.open("", "output", "width=600, height=600, toolbar=no, titlebar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=no, resizable=no, copyhistory=no,"); 
  5.  
  6. output.document.write("word0="+word1_txt.value+"&"+"word1="+word2_txt.value+"&"+"word2="+word3_txt.value+"&"+"word3="+word4_txt.value+"&"+"word4="+word5_txt.value);
  7.  
  8. output.document.execCommand("SaveAs",false,"*.txt")
  9.  
  10. output.close();
  11.  
  12. }
  13.  
  14. </script>
The word1_txt.value are needed for the users input on the main page.

I have recently discovered that i can save as a .doc file and the problem goes, this is ok for a temporary solution however, if it is possible i would rather use .txt.

Cheers
Sep 25 '07 #3

acoder
Expert Mod 15k+
P: 16,027
See this link. Read the section on null bytes.
Sep 25 '07 #4

P: 16
Great! This looks like the kind of thing im after! Ill have a go at integrating this with what i've done at the moment.

Thanks for the help!

Gav
Sep 25 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.