Solved

saveas execCommand with own interface

Posted on 2004-04-13
7
2,456 Views
Last Modified: 2007-12-19
I would like to use execCommand('saveas') but not have the dialog box pop up.

I know by putting execCommand(SaveAs, false, tempcontent.php); perhaps would work, but it doesn't seem to in my code. I figure the format of the filename can't be right or something.  

Can anyone give me a clue as to what the filename should be. I do want it to be exactly the same everytime this command is used, but I don't really care what it is called, as long as I know.

Thanks,
H
0
Comment
Question by:wjdashwood
  • 4
  • 3
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 10830350
It is not possible to avoid the prompt.  That would be a security breach since you could overwrite an important systen file.

This link shows a workaround:
      http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=unUk16U0CHA.428%40TK2MSFTNGP09

It uses the FileSystemObject to save the HTML.   Since that is an ActiveX object, the user will be proyed about using "unsafe objects" so there is still a prompt.

Best to just let the prompt come up.  The user will be promyed, but he will neeed only click the [OK] button.  It is always good to let the user know that you are saving data to his hard disk.

function DoTest() {
      document.execCommand( 'saveas', false, "c:\\temp\\pg.htm" )
}

-- Dan
0
 

Author Comment

by:wjdashwood
ID: 10832078
I don't want to save it to the user's hard disk. I want to save it to a directory hosted at the location of the website.  

What I need is a way of getting all of the data in the editable area and saving it to a file or to a variable.  It doesn't have to be the saveas command, I just thought that would be a handy way of getting all of the data in the editable area, I need the html code to be saved somehow.

Do you have any other suggestions on how I can do it. I don't want the user to be prompted though. They will press the save button and this will start the process. If I wanted a prompt I would create my own to fit with the design of the page.

Thanks,
H
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10837050
If you want to allow the user to upload a file to your server, that is an entriely different issue!

Just use
<FORM method=post ENCTYPE="multipart/form-data" action=your_url >
        <input type=file name="TheFile">
</FORM>

in your HTML.  It displays a textbox and a [Browse...] button.

See:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/input_file.asp

The server will need to be able to handle uploads, but all servers can do that these days.

-- Dan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:wjdashwood
ID: 10841028
The problem is that I have no way of collecting the data. Originally I display it by outputting two variables, one with the css and one with the main html, but as soon as I make a change the variables no longer hold the data. The only way I can think of getting the data back, is by using an execCommand function to save it or select it and somehow copy it. The data is not in a form it is just held within a <div></div>
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10845260
I don't understand you last comment at all.  First you want to know how to download a file and then you want to know how to upload a file, and now there is something about variables and <div> tags....

If you need to maintiain some information on the client machine, the way to do that is to create and save a "cookie"  Use the

     document.cookie

object to do that.  See:
      http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/cookie.asp
0
 

Author Comment

by:wjdashwood
ID: 10858153
I need to somehow save the data which is held in an editable area of a page. I thought this could be done using the saveas function, but apparently not, as I can't do that without a dialog box popping up. So I am now looking for other ways of getting the information.

There is another execCommand which is called selectall. I was considering using this and then somehow getting the selected part into a variable or file. Can this be done?

I already use cookies but it isn't really relevant to what I am doing in this bit.

Sorry I'm struggling to explain exaclty what I'm doing. Thanks for keeping with it.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 10865218
You won't be able to save a file to the user's hard disk without a prompt.  And you won't be able to read that data without a warning prompt.

(exception:  If the page is a local HTML file -- not one sent by a server -- then you can write it as a HTA (Hypertext Application) and the the user will not be prompted about unsafe operations sich as saving files).

Note that the max length of a cookie appears to be 4K (though it might vary by the browser), so unless you have a great deal of data to save, you might look a little bit deeper into using cookies.

If a cookie won't work, then the normal technique would be to post the data back to the server and then, when the user needs that data, the server sends it back to the client.

-- Dan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now