SaveAs Command

R

Repairman2003

I'm using <a href="javascript:document.execCommand('SaveAs', true,
'folder/file.ext')> but it always returns false no matter what because
of the fact that I'm trying to save a file that isn't in the same
folder on the server. Can execCommand() not take an argument for a
file that is locatied in a different folder? How can this be done?
And if I can prepopulate a target location on the user's machine that
would be the best solution, (eg. c:\some folder\). I don't think that
is possible with javascript because of security, but I may be wrong.

window.location() will take in a folder, so I can always fall back on
that.

Thanks,

Matthew
 
T

Thomas 'PointedEars' Lahn

Repairman2003 said:
I'm using <a href="javascript:document.execCommand('SaveAs', true,
'folder/file.ext')> but it always returns false no matter what because
of the fact that I'm trying to save a file that isn't in the same
folder on the server.

You are very confused. First, the SaveAs command saves to the client, so
the location of the server-side resource does not matter. Second, your
`href' attribute value is not properly delimited. Third, don't use
`javascript:' in the `href' attribute of an `a' element, unless you want to
create a temporary document dynamically (which is the intent behind this URI
scheme) or you need it as fallback for `onclick' in a dynamically generated
pseudo-hyperlink. And finally, you can't know the real return value of that
method because you do not evaluate it yet.
Can execCommand() not take an argument for a
file that is locatied in a different folder?

The SaveAs command obviously pops up a "Save As" dialog in which the user
would first select the local directory in which to save the file, and
optionally change the filename or the file format before. It stands to
reason that filenames cannot contain a slash character because it is used
as path delimiter and option prefix already.
How can this be done?

Impossible code can be written in a number of ways. You have just
discovered one, congratulations.
And if I can prepopulate a target location on the user's machine that
would be the best solution, (eg. c:\some folder\).

Of course it wouldn't, because you cannot know which permissions are
required to write to the parent directory, and in particular if the user
running the browser has the necessary privileges.
I don't think that is possible with javascript because of security,
but I may be wrong.

You don't appear to think clearly. "javascript" doesn't even enter into
it, this is a feature of the (MSHTML) DOM. And security has little to do
with it.
window.location() will take in a folder, so I can always fall back on
that.

window.location is not a method to begin with, and it certainly cannot be
assigned a folder, only maybe a URI that refers to a local directory if the
user agent supports that and it complies with the Same Origin Policy.

As I have said, you are really either very confused or completely clueless.
If the former, take a break; if the latter, you should get the basics right
by RTFM before you try to mess with the user's software and filesystem.

<http://msdn.microsoft.com/en-us/library/ms536419(VS.85).aspx>


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,063
Latest member
StormyShuf

Latest Threads

Top