473,322 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Read HTML-code from file

Hi,

I want to write a script that (run from a file on the local HD) 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
<head></head><body></body>

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). Any hints?

Oh, just in case that matters, I'm using Galeon on Linux.

I hope someone out there can help me.

Thanks, Christian
Jul 20 '05 #1
7 18532
Christian Schmitt hu kiteb:

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). Any hints?


Yep. Use a programing language in an environment that actuially has
permission to write a file. This does not apply to javascript running in
teh context of a web browser.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #2


Christian Schmitt wrote:
I want to write a script that (run from a file on the local HD) 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
<head></head><body></body>

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). Any hints?

Oh, just in case that matters, I'm using Galeon on Linux.


This sounds all like a task for server side scripting with PHP or JSP or
ASP.
But I think Galeon is Mozilla based so maybe it offers
XMLHttpRequest
e.g.
if (typeof XMLHttpRequest != 'undefined') {
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'whatever.html', false);
httpRequest.send(null);
alert(httpRequest.responseText);
}
That way you can read text pages from the same server the page with the
script is loaded from.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3


On Fri, 21 Nov 2003, Fabian wrote:
Christian Schmitt hu kiteb:

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). Any hints?


Yep. Use a programing language in an environment that actuially has
permission to write a file. This does not apply to javascript running in
teh context of a web browser.


Well, for several reasons I'm limited to Javascript. And I don't want to
initiate the saving from the script, just create a document that the user
can save manually.

PL
Jul 20 '05 #4


On Fri, 21 Nov 2003, Martin Honnen wrote:


Christian Schmitt wrote:
I want to write a script that (run from a file on the local HD) 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
<head></head><body></body>

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). Any hints?

Oh, just in case that matters, I'm using Galeon on Linux.
This sounds all like a task for server side scripting with PHP or JSP or
ASP.


This all takes place locally, the script is not on a server.
But I think Galeon is Mozilla based so maybe it offers
XMLHttpRequest
e.g.
if (typeof XMLHttpRequest != 'undefined') {
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'whatever.html', false);
httpRequest.send(null);
alert(httpRequest.responseText);
}
That way you can read text pages from the same server the page with the
script is loaded from.

XMLHttpRequest seems to be supported, but hangs the browser :-((
Perhaps because I try to read a local file?
Any other ideas?

PL
Jul 20 '05 #5


Christian Schmitt wrote:
On Fri, 21 Nov 2003, Martin Honnen wrote:
Christian Schmitt wrote:
I want to write a script that (run from a file on the local HD) 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
<head></head><body></body>

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). Any hints?

Oh, just in case that matters, I'm using Galeon on Linux.


This sounds all like a task for server side scripting with PHP or JSP or
ASP.

This all takes place locally, the script is not on a server.


I understand that you are attempting things locally, but it sounds more
like a task to be solved with PHP or ASP or JSP as there you don't run
into the restrictions client side JavaScript has to access the file
system or any Web server.
But I think Galeon is Mozilla based so maybe it offers
XMLHttpRequest
e.g.
if (typeof XMLHttpRequest != 'undefined') {
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'whatever.html', false);
httpRequest.send(null);
alert(httpRequest.responseText);
}
That way you can read text pages from the same server the page with the
script is loaded from.


XMLHttpRequest seems to be supported, but hangs the browser :-((
Perhaps because I try to read a local file?


The third argument to the open() call is the asynchronous mode, in the
example above that is false meaning the send() call later will block the
beowser till the file is loaded.
You can also perform asynchronous requests, then you need to set up an
httpRequest.onreadystate
handler.

If you do not even want to read files via http but only from the local
file system then perhaps XPConnect can do that with Galeon
http://www.faqts.com/knowledge_base/...d/23360/fid/53

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #6


On Fri, 21 Nov 2003, Martin Honnen wrote:
But I think Galeon is Mozilla based so maybe it offers
XMLHttpRequest
e.g.
if (typeof XMLHttpRequest != 'undefined') {
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'whatever.html', false);
httpRequest.send(null);
alert(httpRequest.responseText);
}
That way you can read text pages from the same server the page with the
script is loaded from.

XMLHttpRequest seems to be supported, but hangs the browser :-((
Perhaps because I try to read a local file?


The third argument to the open() call is the asynchronous mode, in the
example above that is false meaning the send() call later will block the
beowser till the file is loaded.


That much I found out already, but why doesn't it load at all? Loading a
small local file should happen instantly.
You can also perform asynchronous requests, then you need to set up an
httpRequest.onreadystate
handler.

If you do not even want to read files via http but only from the local
file system then perhaps XPConnect can do that with Galeon
http://www.faqts.com/knowledge_base/...d/23360/fid/53


But this works only in Mozilla-based browsers, right? I need something
that works in ALL (well, most of the common ones, at least) current
browsers on all platforms.

Christian
Jul 20 '05 #7
VK
> But this works only in Mozilla-based browsers, right? I need something
that works in ALL (well, most of the common ones, at least) current
browsers on all platforms.


Platform independent bugs-free 99% reliable local File I/O interface? If
anyone gets a solution of this, don't post it here, but sell to Sun Java
for a good money. They are poking on the roses with it for a decade now,
and it's still buggy like hell. Too many issues are involved here, and
it would take a dozen of pages just to explain them (besides technical,
a lot of security related).

You have an easy solution with Windows systems with IE installed. Its
implementation of JavaScript (JScript) supports ActiveXObject, which
works just fine with local files. That would cover about 85% of the
potential customers.

The only totally universal solution would be to make a JavaScript editor
and provide an event-driven browser-dependent prompt like "Choose File >
Open to open the file you want to edit" and "Choose File > Save As to
save the changes you've made".
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joe | last post by:
I am trying to read the EventLog of different servers on the network. If I run the script in a command line, it works well. But when I try to put the script into the Web server (IIS in Windows...
0
by: Otis Roth | last post by:
----F34848E08D128A79C Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled...
2
by: Michael Winter | last post by:
Below is the IDL definition of the HTMLOptionElement. interface HTMLOptionElement : HTMLElement { readonly attribute HTMLFormElement form; attribute boolean defaultSelected;...
119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
1
by: Stefan Mueller | last post by:
I'd like to read and modify a cell (e.g. 'Text 1') in the following HTML table with a JavaScript: ============================================== <html> <body> <table id = "MyTable"> <tr id...
2
by: Mitch | last post by:
I have some simple HTML I'm trying to read with the XMLTextReader. As in the MSDS examples, I set up a loop to read each XML node: while (reader.Read()) { switch (reader.NodeType) { case...
4
by: Danil Dotsenko | last post by:
Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's SuperKaramba widget. (http://www.kde-look.org/content/show.php?content=32185) I was using 2.4.x python docs as reference and...
2
by: Jim S | last post by:
I have a need to read the contents of an html table on a remote web page into a variable. I guess this is called screen scraping but not sure. I'm not sure where to start or what the best...
1
by: ZelluX | last post by:
Hi, all I'm confronted with some trouble when dealing with html files. The html files contain javascript and some information stored in tables. And it seems that they're not well-formed, when...
0
by: JosAH | last post by:
Greetings, It is strongly advised to download the first two links to your computer. The first link downloads Sun's Java Tutorial which is an almost mandatory read if you want to get started...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.