...

View Full Version : Access to source code?



GDS
08-23-2002, 11:21 AM
Is it possible, by scripting, to get access to the complete source code of a document, as you see it if you right-click on a page?

(That is, the original source before any scripting etc. has occured.)


GDS

martin_narg
08-23-2002, 02:32 PM
Reading http requests thru browsers/scripting?

You may or may not be able to use your browser to do this. Netscape 4.x shows you all dynamically written html as plain html, mozilla/ie shows you the scripting but not the resultant html (only the formatted stuff in the browser window - you can see it graphically).

Data going over HTTP is unencrypted - it's plain text so any program that can allow you to view textual http requests will work. There are hundreds out there - cURL (http://curl.sourceforge.net/) netcat (http://www.atstake.com/research/tools/) are just two of many that are fairly easy to use. - I just give both of these a thumbs up because of their usefulness for information finding :thumbsup: - you can use an activeX script to initiate these programs, then read out the content of the resultant file.

You could write a bit of client-side FSO(FileSystemObject) to download the page from the server into an iframe, then drop the html from your browser cache folder as text onto the page.

Hope this helps and didn;t get too bogged down and unreadable, I would imagine/hope someone out in the ether has a better way than any I've mentioned, it's an interesting question :D

m_n

GDS
08-24-2002, 10:32 AM
tanks for your reply, martin_narg.

martin_narg wrote:
* Reading http requests thru browsers/scripting?

Well, not exactly, I "only" want to load the original html-text
for a given frame into a javascript variable.
It already is there, but I don't know how to get hold of it.


martin-narg wrote:
* you can use an activeX script to initiate these programs,
* then read out the content of the resultant file.

This solutions seems to be a little bit complex.
It reqires downloading a program, and I really don't know
how to use activeX.

martin-narg wrote:
* You could write a bit of client-side FSO(FileSystemObject) to
* download the page from the server into an iframe, then drop
* the html from your browser cache folder as text onto the page.

The use of FSO certainly will solve the problem, but I feel this
as a over-kill as long as the HTML-text already is there.

The reason I asked this question is that I am makeing a simple
HTML editor in javascript. It works fine, but if the content is
changed during loading, then I no longer have a unmodified
source to work on.

One solution would be to turn off scripting completely
for one frame only, but I think that is not possible? :confused:


GDS

jkd
08-24-2002, 04:56 PM
You can retrieve the dynamic page source as a string:

IE:

document.documentElement.outerHTML;

Moz:

(new XMLSerializer()).serializeToString(document)

GDS
08-24-2002, 10:04 PM
jdk wrote:

* You can retrieve the dynamic page source as a string:
* IE:
* document.documentElement.outerHTML;


Your solution will not do the job for me,
as this is the dynamically changed source.
Consider this code:


<html>
<head>
<title>get source</title>

<script>
function getSource(){
var S=document.documentElement.outerHTML;
alert(S)
}
</script>

</head>
<body>
<button onclick="getSource()">get Source</button>

<script>
document.write("This stuff is <i>scripted</i> into the document!")
</script>

</body>
</html>


If you hit the button, you will get some kind of reformatted code, as it looks after the document.write has done the job.

There is also some minor changes, the small letters in html tags is changed to big letters and whitespace is not the same.

(I have not tested the Moz version yet.)


GDS

jscript_junkie
08-24-2002, 10:59 PM
What you want is:

javascript:(function(){%20function%20htmlEscape(s){s=s.replace(/&/g,'&amp;');s=s.replace(/>/g,'&gt;');s=s.replace(/</g,'&lt;');return%20s;}%20x=window.open();%20x.document.write('<pre>'%20+%20htmlEscape('<html>\n'%20+%20document.documentElement.innerHTML%20+%20'\n</html>'));%20x.document.close();%20})();

Remove the space between javascript: and (function. I only did this because it causes a frown to occur when posting.

<edit my="post" />
Fixed a frown bug described in the above paragraph.

GDS
08-25-2002, 07:58 AM
jscript_junkie:

The probem is that I don't have access to the untampered source code, as you see it when you select View source from the menu.

If you try my script posted earlier, you will see that the
alert also includes the text scripted by the document.write().

GDS

martin_narg
08-25-2002, 12:02 PM
hmm, try this?



<html>
<head>
<title>view source</title>
<script language=JavaScript>
function ViewSource() {
window.location = "view-source:" + document.location.href }
</script>

</head>
<body bgcolor="white">
<form name="myForm">
<input type="button" name="myButton" value="view source" onClick="ViewSource()">
</form>
<br><br>
<script>
document.write('hello world');
</script>
</body>
</html>

GDS
08-25-2002, 10:03 PM
Cut copy and paste isn't the most elegant interface for loading
a file into an html editor. Ok, there seems to be no shortcut here.



The use of FSO, as martin_narg mentioned earlier, will actually
solve my problem. Besides, I can use it as a hta application,
to get rid of those annoying alerts when useing FSO. :)

But I am wondering: why are we denied to get easy access to
the untampered source code? :confused:

GDS

joh6nn
08-25-2002, 10:14 PM
'cause microsoft sucks.

if you need help with the FSO, and reading files, let me know.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum