473,396 Members | 1,797 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,396 software developers and data experts.

Simple HTML read/write question

I would like to first state that I have searched through the archives
and found a lot of related material, but am still new enough to
javascript that I can't fit all the pieces together yet. So here is my
situation.

I would like to create a program that grabs the source of a displayed
webpage, sends it off to another [external] program, then receive the
slightly modified source back from that other program, and then reposts
the slightly modified source code back to the origonal page.

What I am hoping to get from this group is a few leads.

(1) It is possible to write the contents of a webpage as an output
stream?
(2) Is it possible to completely overwrite the source code of a webpage
with new source code?
(3) Could I put this kind of functionality in a bookmarkelt/favelet?

Could you shoot me a few idea's as to how this is done. Thanks!!

Nov 23 '05 #1
17 3410

ch***********@gmail.com wrote:
I would like to first state that I have searched through the archives
and found a lot of related material, but am still new enough to
javascript that I can't fit all the pieces together yet. So here is my
situation.

I would like to create a program that grabs the source of a displayed
webpage, sends it off to another [external] program, then receive the
slightly modified source back from that other program, and then reposts
the slightly modified source code back to the origonal page.
Hi. Why do you want to do this? I would be helpful to understand the
objective.
What I am hoping to get from this group is a few leads.

(1) It is possible to write the contents of a webpage as an output
stream?
It is possible to read a remote web page into a string using the
responseText property of the HTTPRequest object.
(2) Is it possible to completely overwrite the source code of a webpage
with new source code?

[snip]

Do you mean overwrite it on a remote web server or on your local
machine?

If you mean on your local machine, then you can use
Scriping.FileSystemObject (IE) or XPCOM (Mozilla), to read and write
local files from Javascript/JScript.

If you mean overwite it on a remote web server which you do not
control, then obviously no: think of the security implications. I
assume you don't mean this.

If you mean overwrite it on a remote server you control, then you could
either:-

- Overwrite the file using FTP. Javascript does not have FTP
natively, so you would need some form of component to do this.
- Create a web page on that server using ASP, PHP etc, that can
receive and process a POST request from an HTTPRequest, and use file
save components on that server. If it is a UNIX server, remember to
set the appropriate file access permissions.

Julian

Nov 23 '05 #2
Yes, I would like to overwrite it on my local machine.

The basic concept is the following: I would like to take a webpage that
has some sort of encrypted data on it. Run my java script...and have it
replace the encrypted data with unencrypted data.

Thanks for your help

Nov 23 '05 #3

ch***********@gmail.com wrote:
Yes, I would like to overwrite it on my local machine.

The basic concept is the following: I would like to take a webpage that
has some sort of encrypted data on it. Run my java script...and have it
replace the encrypted data with unencrypted data.

Thanks for your help


Hi. In which case, it sounds like you just need to learn about file
handling components that ship with IE and Firefox.

I.e. I am assuming that you want to load a web page as a string from a
given directory on your machine, process it as a string, and then save
again on the local computer.

As noted, there are two sets of file handling options available:-

1. For Internet Explorer

Scripting.FileSystemObject - an ActiveX object. Search in particular
on the Microsoft MSDN web site.

2. For Firefox

There are load and save functions at the end of the following page:-

http://www.captain.at/programming/xul/

Julian

Nov 23 '05 #4
VK
> http://www.captain.at/programming/xul/

Does it really work for you w/o second privilege for
"UniversalFileRead"?
If so, what Firefox version are you using?

Nov 23 '05 #5

VK wrote:
http://www.captain.at/programming/xul/


Does it really work for you w/o second privilege for
"UniversalFileRead"?
If so, what Firefox version are you using?


Sorry, not quite sure what you mean. I must confess to only having
Mozilla 1.6. Have not tested on Firefox yet. Does it not work on
Firefox? Have you checked security settings.

If I have understood you correctly, AFAIK you need to use

netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");

in every function that is using a component. It is not like ActiveX,
create one time, use many times. With UniveralXPConnect you must
enable privileges in each function and nested function that uses it.

Regards

Julian

Nov 23 '05 #6
<ch***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I would like to first state that I have searched through the archives
and found a lot of related material, but am still new enough to
javascript that I can't fit all the pieces together yet. So here is my
situation.

I would like to create a program that grabs the source of a displayed
webpage, sends it off to another [external] program, then receive the
slightly modified source back from that other program, and then reposts
the slightly modified source code back to the origonal page.

What I am hoping to get from this group is a few leads.

(1) It is possible to write the contents of a webpage as an output
stream?
(2) Is it possible to completely overwrite the source code of a webpage
with new source code?
(3) Could I put this kind of functionality in a bookmarkelt/favelet?

Could you shoot me a few idea's as to how this is done. Thanks!!


This is sort-of what you want, I think.

1) It grabs the source of a URL
2) It modifies part of it; (xTXT replaces sTXT)
3) It replaces the current page
(.innerHTML doesn't work in all browsers)
4) It doesn't resolve relative paths (e.g. images).

Watch for word-wrap.

<html>
<head>
<title>Googler.htm</title>
<script type="text/javascript">
function Googler() {
var sURL = "http://www.google.com/index.html";
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sURL,false);
oXML.send();
try {
var sXML = oXML.ResponseText;
var sTXT = "&copy;2005 Google"
var xTXT = This page has been modified by Googler!"
var iTXT = sXML.indexOf(sTXT
var sHTM = sXML.substr(0,iTXT) + xTXT +
sXML.substr(iTXT+sTXT.length);
document.body.innerHTML = sHTM;
} catch(e) {
alert(sURL + " not found!");
}
}
</script>
</head>
<body onload="Googler()">
</body>
</html>
This version adds a <base href=''> tag after the <body> tag to resolve
relative paths.

<html>
<head>
<title>Googler.htm</title>
<script type="text/javascript">
function Googler() {
var sURL = "http://www.google.com/index.html";
var xURL = sURL.substr(0,sURL.lastIndexOf("/")+1);
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sURL,false);
oXML.send();
try {
var sXML = oXML.ResponseText;
// Replace the value of sTXT with the value of xTXT.
var sTXT = "&copy;2005 Google";
var xTXT = "This page has been modified by Googler!";
var iTXT = sXML.indexOf(sTXT);
var sHTM = sXML.substr(0,iTXT) + xTXT +
sXML.substr(iTXT+sTXT.length);
// Insert <base href=''> after the <body> tag.
var sTAG = "<body";
var iTAG = sHTM.toLowerCase().indexOf(sTAG);
var jTAG = sHTM.substr(iTAG).indexOf(">") + iTAG;
var xTAG = "<base href='" + xURL + "'>";
sHTM = sHTM.substr(0,jTAG+1) + xTAG + sHTM.substr(jTAG+1);
// Replace the page's source code.
document.body.innerHTML = sHTM;
} catch(e) {
alert(sURL + " not found!");
}
}
</script>
</head>
<body onload="Googler()">
</body>
</html>

There are probably flaws with this approach which others will tell us.
Nov 23 '05 #7
VK

Julian Turner wrote:
If I have understood you correctly, AFAIK you need to use
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");


You're absolutely right. Mozilla is using Netscape 4.x Java security
model for XPConnect (despite it is not Java based anymore).

You *always* have to ask for UniversalXPConnect first:
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");

It gives you privilege to use XPConnect per se (create class instances
etc.) but rather useless without a privilege to do something outside
the sandbox.

In the particular in order to access local file system you have to ask
for additional privilege: either UniversalFileRead or
UniversalFileWrite.

So the combined code will be:
....
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
netscape.security.PrivilegeManager.enablePrivilege ("UniversalFileRead");
....
otherwise even with UniversalXPConnect enabled you will not be able to
access local files.

It works this way at least for Firefox under Windows 98 / XP - and it
should work this way. All this of course for default security settings.

Here my original post with the code sample:
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/7cd482713658987b/61b24d432da604b8>

Unfortunately Mozilla did not implement (yet?) Netscape's macro
targets.
In Netscape you had
Primitive targets (like "UniversalFileRead", "UniversalFileWrite")
Macro targets (like "UniversalFileAccess")

You may find interesting this forgotten lore which become recently once
again actual:
<http://web.archive.org/web/20010309004241/developer.netscape.com/docs/manuals/signedobj/capabilities/index.html>

P.S. And where are the promised code samples from you ? ;-)

Nov 23 '05 #8
McKirahan wrote:
function Googler() {
var sURL = "http://www.google.com/index.html";
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sURL,false);
oXML.send();
try {
Since you cannot test for ActiveX objects, the
NewExpression has to be within the `try' block.

And I think it should be open(), not Open().
There are probably flaws with this approach which others will tell us.


[x] done
PointedEars
Nov 23 '05 #9
THANKS A TON for all your help. This was way more then I expected!!

Nov 23 '05 #10
<ch***********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
THANKS A TON for all your help. This was way more then I expected!!


Your very welcome.

Be aware, though, that the <base href=''> tag will not resolve relative
paths in the body tag (e.g. "background=") nor those in scripts or CSS.
Nov 23 '05 #11

VK wrote:
P.S. And where are the promised code samples from you ? ;-)


If you look at the original thread you requested them on, you might
find them. I posted them yesterday (my time).

Julian

Nov 23 '05 #12
VK
Got it!

Great thanks!

Nov 23 '05 #13

VK wrote:
Got it!

Great thanks!


Good. I know the code nothing special, but let me know how you get on.
I use it just for my own private applications, but I have not tested it
in anger , and it is a bit of a hack, so I fully expect the code to
fall over or some unexpected twist to reveal itself.

Julian

Nov 23 '05 #14
VK

Julian Turner wrote:
Good. I know the code nothing special, but let me know how you get on.
I use it just for my own private applications, but I have not tested it
in anger , and it is a bit of a hack, so I fully expect the code to
fall over or some unexpected twist to reveal itself.


Yes, I think that in the first release of jsFileManager I limit myself
with the original set:
1) Display full directory info with multiple file selection.
2) Read/Write/Create/Delete text files (.txt and .html)
3) Launch applications

This alone takes a lot to test for full IE/Gecko compatability. I guess
it is better to have lesser features but working right rather than more
features with some bombs in them :-)

I definitely would like to implement later binary read/write and base64
codec. If binary I/O indeed can be implemented on IE only via VBScript,
I'll use
window.execScript(code,'VBScript') wrapper to keep one js-only library.

Nov 23 '05 #15

VK wrote:

[snip]
I definitely would like to implement later binary read/write and base64
codec. If binary I/O indeed can be implemented on IE only via VBScript,
I'll use
window.execScript(code,'VBScript') wrapper to keep one js-only library.


I am looking at this as purely academic interest (being a hobbyist, not
a professional), to create an ASP web page to enable me to manage files
on my server remotely as an alternative to FTP.

I was not aware of that function. I will have a look at it. I have
been dynamically creating script tags.

I am also looking at what scriptable I/O streams Firefox has, and will
share the results.

Finally, I am exploring creating a Java applet to do base64 encoding,
as this is a slow process with Javascript for files >100k.

We are well off topic now, so I'll say nothing more.

Julian

Nov 23 '05 #16
Sorry, one final thing (as original thread is closed), take a look at
this for a complete library:-

<URL:http://www.henk-reints.nl/cgi-bin/getsrc?http://henk-reints.nl/jscript/js/hr$binstring.js>

Julian

Nov 23 '05 #17
VK

Julian Turner wrote:
Sorry, one final thing (as original thread is closed), take a look at
this for a complete library:-

<URL:http://www.henk-reints.nl/cgi-bin/getsrc?http://henk-reints.nl/jscript/js/hr$binstring.js>


Julian Turner, you're my hero!
:-))
<TOPIC IS CLOSED>

Nov 23 '05 #18

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

Similar topics

4
by: Richard Shea | last post by:
Hi - I'm new to Python. I've been trying to use URLLIB and the 'tidy' function (part of the mx.tidy package). There's one thing I'm having real difficulties understanding. When I did this ... ...
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
18
by: Geoff Cox | last post by:
Hello, I am trying to print out the array values for a second time but get error on page message? Thanks Geoff <html>
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
1
by: Kenny ODell | last post by:
I am struggling a bit with XML, even as I wade through endless help files and several books. I thought it would be useful to toss my particular needs to the group to see what you think is the best...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
1
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
5
by: fussfart | last post by:
I'm trying to do something that should be very simple but isn't working! (I also want to do something somewhat more complicated, but that has to wait until I figure out the simple stuff.) First, I...
1
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.