473,414 Members | 1,878 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,414 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 18534
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.