Opening MS Word/XML file generated with javascript

W

Wizfrog

Hello...

I'm developping a client-side application with XML and Javascript.
The idea is that it could run off-line in a browser, using a
previously downloaded XML database, or could run of a server if it is
scaled to very many users... but for now, it is to be ran off-line
primarily.

I want to generate a MS Word document in XML (i can do that) from the
data in the XML DB, but mostly I want to be able to open the generated
document AS an MS Word document.

in this example:
http://www.codeproject.com/office/Wordyna.asp

the file is generated on the server, and the HTTP header is set so
that it opens as a Word file.

So, I need to open a new window and be able to set the http Header
Content-Type as "application/msword".

and maybe also "Content-Disposition" as attachement or something..

I just don't know how it is possible to open a new window with a
specific HTTP Header in Javascript. I know Javascrit cannot CHANGE the
http header of the page it's runnig from, but can it open a new window
with a given HTTP header?

I can open a new window and dump my XML there, but then what? If I use
a script to "save", I run into security issues, if I ask the user to
use "save as" in the browser, it won't save with .DOC extension, and
if I open Word with JScript, there are the security issues again.

Any suggestions welcome!
 
W

Wizfrog

Wizfrog said the following on 7/12/2007 6:14 PM:













You have to set those headers on the server. If it is running locally,
you are out of luck.


And you have other issues as well:

1) User doesn't have MSWord.
2) User has the browser set to display .doc files in the browser.
3) User has a different program to handle .doc files.

If it is running locally, in the Local Zone, you have some relaxed
security settings but not totally free.

If you are sure the users will have MSWord and running IE, you could
look into an .hta application instead so it runs in a totally different
security environment.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/- Hide quoted text -

- Show quoted text -

what about sending the whole data through a POST or GET form? is there
any way to set the content type of a NEW window from the client?
I guess I could open a new URL with .HTA and pass the data to it?
 
W

Wizfrog

Wizfrog said the following on 7/12/2007 6:48 PM:



You can set some headers on an XMLHTTPRequest but not when simply
opening a new window.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

XMLHTTPRequest does not seem to work with local files (or file:// url
for that matter)... so no luck there either.

HTA always asks to open or save, and that is annoying.
I could open a blank Word document, but then I can't write to it from
my script...

XLST-FO allows to generate PDF files, right, so it's the same idea.
Does that only work from the server too?
 
W

Wizfrog

Then you obviously didn't test it. XMLHttpRequests work just fine
locally, only you cannot expect any HTTP-dependent behaviors to work.

well... this is the code and it gets me to the alert box saying "there
was an issue retrieving the XML data" so it's either not finished or
can' find it.

<html>
<head>
<script type="text/javascript">
var xmlhttp

function loadXMLDoc(url)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{ xmlhttp=new XMLHttpRequest() }
// code for IE
else if (window.ActiveXObject)
{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") }
if (xmlhttp!=null)
{ xmlhttp.onreadystatechange=onResponse;
xmlhttp.open("GET",url,true);
xmlhttp.send(null); }
else
{ alert("Your browser does not support XMLHTTP.") }
}

function checkReadyState(obj)
{ if(obj.readyState == 4)
{ if(obj.status == 200)
{ return true;
}
else
{ alert("Problem retrieving XML data"); }
}
}

function onResponse()
{ if(checkReadyState(xmlhttp))
{
var response = xmlhttp.responseXML.documentElement;
txt="<table border='1'>"
x=response.getElementsByTagName("Item")
.....

document.getElementById('copy').innerHTML=txt
}
}
</script>
</head>
<body onLoad="loadXMLDoc('database.xml');">
<div id="copy"></div>
</body>
</html>
 
W

Wizfrog

Or you totally ignored what I said. Using XMLHttpRequests locally will
not have HTTP-specific behaviors.

So, testing the "status" property of your XMLHttpRequest object will not
work locally.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.- Hide quoted text -

- Show quoted text -

Dude,

Do I seem like I know all about XMLHTTPRequests here?
I'm here asking questions, and looking for answers, not to be told I'm
totally stupid. obviously, I know I'm not the expert in XML here, so
it would be nice if the people who want to help would take that into
account.

So, if I'm not supposed to check on the Requst Status, what do I do
from there?
My goal, again, is to open a new window with my XML to be interpreted
as a Word document.
So, I load a file through the XMLHTTPRequest and I set the header to
read it as content-type application/msword
but then what? How do i actually get to open a window with this
document and content type?
It seems to me that this is not really getting me where I want: I can
open any file with any content type, but then I'm left with that data;
it doesn't help opening the window I want in the proper content type
to display my word document...

So I tried something else: opening a page with an iframe that include
a .doc , or even of Object that had msword data in it.
it does open, but then I'm still stuck with the problem of transfering
my XML data into the document.
it seems like i have to save the file to disk, then open it with Word
with JScript.
That's a pain in the butt.
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top