470,648 Members | 1,657 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

Read HTML-code from file (2nd attempt)


I posted this on Friday, but didn't get a satisfactory answer. Therefoer I
post it again with some clarifications.

I want to write a script that (run from a file on the local HD,
therefore I can't use server-side stuff) reads another local html-file
into a variable, then make some changes to it, and then output the result
in a way that makes it simple for the user to save it again. And all of
this should run in any current browser, not just IE.

I managed to access the code of the current document by
code = document.documentElement.innerHTML

But when I open another window with the file I want to edit, all I get is
if I do code = otherWindow.document.documentElement.innerHTML

Is there no easy way to do this?!?

For the output I tried to do document.write in an output window, but I
can't save the code I generate there, all I get is the sourcecode of my
script page (the opener of the page I try to save). I don't want to
save under script-control, but manually by clicking Save-As. If there
is no simple solution to this, I still can write the code to a textarea
and have the user copy and paste it into an editor. So the most
important part is reading the code. But I'd like to have it a bit more
comfortable. Any hints?

Oh, just in case that matters, I'm using Galeon on Linux.
But I want this to run also in other browsers, so I can't use
browser-specific code. If nothing else helps and you can help me with
specific code for different browsers I could probably use browser
detection, but I would prefer to keep it simple.

I hope someone out there can help me.

Jul 20 '05 #1
2 1475
As far as I know, there really is no browser independent way to do this
even when using Java. Mozilla seems to hang when using Java for file
reads, etc.

You're stuck with IDing the browser and branching to the appropriate
code. Martin Honnen has given a link to a page I posted on how one can
do local reads in Mozilla, he also has posted many times the code for IE
and NN4 that does file i/o in this news group. Jim Ley also has an FAQ
that is posted here many times and references his page on how to get a
file into a variable using and XMLHTTPRequest.

See if Java works for other browsers.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
I created something for you to use in MSIE only, but my emails and attachments
have been bounced back as 'server not accepting mail'. Please contact me if
you read this and let me know a working email address I can send the code to.

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael Winter | last post: by
1 post views Thread by ZelluX | last post: by
reply views Thread by JosAH | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.