Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Saving Dynamic HTML

5 views
Skip to first unread message

Christoph Basedau

unread,
Jan 16, 2003, 8:03:09 PM1/16/03
to
Hi

when you are using dhtml functions like insertAdjacentHTML
or createTextNode, createElement and so on, or use the about:-protocol,
you can add content to a HTML-Doc that initially just is
a blank doc as: "<html><body></body></html>"
if you reload the doc, all dynamic content is lost.
now i'd like to know, if there is a way to save the content
of a manipulated doc to file?
let's say you have added a table, with some rows and cells
(if the doc is the output from a script) and now you want to save
the content to file?
if you do execCommand "saveAs" it's probably only the template and not
the actual contents that will be saved.
Will it work with fso.write-methods and document.body
and how can i get the rest (head,script,style-sections)

thanks for your assistance

Christoph


continued in:
ie55.programming.dhtml.scripting

Ed Elliott [MS]

unread,
Jan 20, 2003, 11:33:20 AM1/20/03
to
Hi Christoph,

I think there are a couple of different ways to achieve what it is you want
to do and these depend on whether you have total control over the pages or
not.

I would think the easiest way to save the entire page is to get the
.outerHTML from the <HTML> tag, either give the tag an id and reference it
directly or do a document.getElementsByTagName("HTML")[0].outerHTML.

If your documents also include the DOCTYPE declaration at the beginning then
these won't be picked up so you will need to check for that as well
(document.getElementsByTagName("!")[0].text - should do it)

This won't pick up any scripts (or other external files like stylesheets)
which are in a separate js file and referenced using <script
src="script.js"> but if you specifically have to use these then you could
check all the script tags and see if there is an src attribute, if it is
then download the files separately.

I would then use the fso as you mention below.

--
Ed Elliott
Microsoft UK - Internet Explorer

This posting is provided "AS IS" with no warranties, and confers no rights.

"Christoph Basedau" <cebit_...@gmx.net> wrote in message
news:b07kpu$ac4$04$1...@news.t-online.com...

Message has been deleted

Ed Elliott [MS]

unread,
Jan 22, 2003, 12:06:47 PM1/22/03
to
No problem Christoph,

Can I suggest that for getSourceFile() the MSXML Http object will let you
download the file which you could use the fso to save to the local file
system.

Good luck.

ed


--
Ed Elliott
Microsoft UK - Internet Explorer
This posting is provided "AS IS" with no warranties, and confers no rights.

"Christoph Basedau" <cebit_...@gmx.net> wrote in message

news:#DlY4AYwCHA.2904@TK2MSFTNGP09...
> on 20.01.03 17:33, Ed Elliott [MS] wrote:
> > Christoph Basedau wrote:
>
> [Save generated dynamic HTML-Content to File]


>
> > I think there are a couple of different ways to achieve what it is you
want
> > to do and these depend on whether you have total control over the pages
or
> > not.
> >
> > I would think the easiest way to save the entire page is to get the
> > .outerHTML from the <HTML> tag, either give the tag an id and reference
it
> > directly or do a document.getElementsByTagName("HTML")[0].outerHTML.
>

> Hi Ed,
> Thanks very much. That just works great and really catches
> the actual content. Exactly what i've been looking for.
> innerText works aswell.


>
> > If your documents also include the DOCTYPE declaration at the beginning
then
> > these won't be picked up so you will need to check for that as well
> > (document.getElementsByTagName("!")[0].text - should do it)
>

> Interesting, sometimes the doctype is relevant.


>
> > This won't pick up any scripts (or other external files like
stylesheets)
> > which are in a separate js file and referenced using <script
> > src="script.js"> but if you specifically have to use these then you
could
> > check all the script tags and see if there is an src attribute, if it is
> > then download the files separately.
>

> Something like
>
> var scripts = document.getElementsByTagName("SCRIPT");
> for (i=0;i<scripts.length;i++){
> if (scripts[i].src!='') getSourceFile(scripts[i].src);
> }
>
> where getSourceFile() is yet to be implemented...


>
>
> > I would then use the fso as you mention below.
>

> Thx very much,
> now i can 'record' my scripts output.
>
> Christoph

Cybarber

unread,
Jan 23, 2003, 7:04:56 AM1/23/03
to
you can use a defaultBehavior called userData.
It acts like a large cookie and can store the page in an XMLstore.
Lookup userData behavior in MSDN library.
 
Cybarber
"Christoph Basedau" <cebit_...@gmx.net> schreef in bericht news:b07kpu$ac4$04$1...@news.t-online.com...

Bill Fletcher

unread,
Feb 10, 2003, 4:46:54 PM2/10/03
to
I developed this function for that purpose. Note I allow users to load and
edit an HTML file (created from XML rendered by an XSLT), then save the
changed file. As implemented the edited file is saved with the extension
.hta both to avoid overwriting the original and to force it to load in IE --
I use some features that Netscape does not support.

Viel Erfolg!

Bill Fletcher

function saveCurrentPage()
{
var savefile = "Save these changes to file named";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var rxOnlyFilepath;
var savepath;
var sourcepath = new String(window.document.location);
var rxOnlyFilepath = new RegExp("file:\/+(.*)");
var savepath = sourcepath.match(rxOnlyFilepath);
savepath = unescape(RegExp.$1) ;
if (savepath.length < 1)
{
// If not a local file assume from online or xml; get filename part
rxOnlyFilepath = new RegExp("http:\/\/.*\/(.*)");
savepath = sourcepath.match(rxOnlyFilepath);
savepath = unescape(RegExp.$1);
if (savepath.length < 1)
{
savepath = window.document.title;
if (savepath.length < 1)
{
if (lastsavepath.length < 1)
{
savepath = prompt(savefile, "Edited Report");
if (savepath != null)
{
lastsavepath=savepath;
}
}
else
{
savepath = lastsavepath;
}
}
// There may be illegals in the window title; is this an exhaustive
list?
if (savepath != null)
{
savepath = savepath.replace(/[:\?\\\/\[\]\{\}]/g, "_")+ ".hta";
savepath = savepath.replace(/_+/g, "_")+ ".hta";
}
}
if (savepath != null)
{
savepath = fso.GetAbsolutePathname(".") + "\\" + savepath;
}
}
if (savepath != null)
{
// Save all types as .hta to ensure proper playback
savepath = savepath.replace(/\.ht.+.?$|\.xml$/, ".hta");
if (fso.FileExists(savepath))
{
if ( !(confirm("Replace existing file\n" + savepath + " ?")) )
{
savepath = prompt(savefile, savepath);
}
}
}
if (savepath!=null) // not redundant - - could have come from cancelled
prompt
{
var ForWriting= 2;
var tf = fso.OpenTextFile(savepath, ForWriting, true);
tf.Write(window.document.documentElement.outerHTML) ;
tf.Close();
alert("Changes saved to\n" + savepath);
tf=null;
}
else
{
alert("Save cancelled by user.");
}
fso=null;
}


"Christoph Basedau" <cebit_...@gmx.net> wrote in message

news:b07kpu$ac4$04$1...@news.t-online.com...

0 new messages