Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Document Elements?

Status
Not open for further replies.

mattscotney

Programmer
Jul 31, 2002
57
AU
Hi everyone,

How can I access "document.documentElement"'s from a page using asp?

Thanks in advance,
Matt Scotney
 
XML DocumentElements or page documentElements?
If you could provide us with a starting place (like your variable initializations and object instantiation) we could give you some specific advice or help on this.
-Tarwn "Customer Support is an art not a service" - marketing saying
"So are most other forms of torture" - programmers response
(The Wiz Biz - Rick Cook)
 
Tarwin,

I am trying to access page document elements such as document.documentElement.innerHTML from a regular html page using ASP.

EXAMPLE:
A user enters a url into a input text box, through asp the page is loaded into a new window. I need to extract the document.documentElement.innerHTML from the page I have loaded into the new window.

Currently I can generate the page in the new window using the InetCtls.Inet or Microsoft.XMLHTTP but both objects do not give me access to the innerHTML element. I can also generate the source of the page once it is loaded and display it, however I need an object which can access the document.documentElement.innerHTML.

I can also generate the new page using ASP and by adding a onLoad event to the page generated, run a Javascript function to generate the innerHTML with the following code:
function show()
{
z = window;
z.document.write(header + '<pre>' + repl('<HTML>\n' + document.documentElement.innerHTML + '\n</HTML>'));
z.document.close();
}

function repl(x)
{
x=x.replace(/&/g,'&');
x=x.replace(/>/g,'>');
x=x.replace(/</g,'<');
return x;
}


However I would prefer to do the whole process server side with ASP. Any ideas?

Thanks,
Matt Scotney
 
Your only option would be to parse out the tags you wish to manipulate and make changes using concatenated substrings of the the whole page to the left of the tag and the whole page to the right of the tag with your addition in the middle.
ASP can't manipulate HTML document elements because it is a server-side script and generally is generating the html on the fly, so it did not seem like it needed to access any kind of document object model.
Your two options are using javascript above and the following parsing in ASP:
1) Define a function that accepts a beginTag, and endTag, and a newContent string
2) Using InStr(contentString,beginTag)+len(beginTag) as your starting position, get the left side of the contentString and store it in a variable. Do the same for the right side. Now you can concatenate leftSide & newContent & rightSide to create a new &quot;innerhtml&quot; between the tags.
or if you simple want the contents between the tags you can use the same method, just return the text between beginTag and endTag using InStr to get their positions and mid to get the charact string between the positions.
-Tarwn &quot;Customer Support is an art not a service&quot; - marketing saying
&quot;So are most other forms of torture&quot; - programmers response
(The Wiz Biz - Rick Cook)
 
Tarwin,

Firstly thanks for your help in this matter. I will show you what I have produced so far, if you can work out a way to do the whole process server side it would be wonderful, however from your previous answer I doubt it can be done?

Name this file dSource.htm. This is the file which the user enters the url (file to run in the browser):

<HTML>
<HEAD>
<title>SOURCE</title>
</HEAD>
<BODY>

<P Align = &quot;center&quot;><B>

<form name =&quot;userTxt&quot; method=&quot;post&quot; action=&quot;dSource.asp&quot; target=&quot;dSource&quot;>
URL:
<input type=text name=txtURL value=&quot; size =&quot;40&quot;>
<input type=submit value=&quot;REVEAL SOURCE&quot;&quot;>

</form>
</B></P>
</BODY>
</HTML>


Name the next file dSource.asp:
<%@ LANGUAGE=&quot;vbScript&quot; %>

<HTML>
<HEAD>
<SCRIPT language=&quot;JavaScript&quot; src=&quot;dSource.js&quot;></SCRIPT>
</HEAD>
<BODY onload =&quot;show()&quot;>

<%

function getText()

Dim ipADD, userIN, inet, strHTML, sesArray(2)

userIN = trim(Request(&quot;txtURL&quot;))
ipADD = Request.ServerVariables(&quot;REMOTE_ADDR&quot;)

response.write &quot;<B><FONT COLOR = RED>PLEASE WAIT - GENERATING DECRYPTED SOURCE.......</FONT></B><HR>&quot;
response.write &quot;<FORM NAME=&quot;&quot;tempFORM&quot;&quot;><INPUT Type=&quot;&quot;hidden&quot;&quot; Name=&quot;&quot;userIN&quot;&quot; Value=&quot;&quot;&quot; + userIN + &quot;&quot;&quot;>&quot;
response.write &quot;<INPUT Type=&quot;&quot;hidden&quot;&quot; Name=&quot;&quot;ipADD&quot;&quot; value=&quot;&quot;&quot; + ipADD + &quot;&quot;&quot;></FORM>&quot;

set inet = CreateObject(&quot;InetCtls.Inet&quot;)
inet.requesttimeout = 60 'in seconds
inet.URL = userIN

logREQUEST userIN, ipADD

strHTML = inet.OpenURL
getText = strHTML

end function

sub logREQUEST(url, ip)

Dim logFSO, Writelog

Set logFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set Writelog = logFSO.OpenTextFile(&quot;D:\Abyss Web Server\htdocs\Spider\log.txt&quot;, 8, True)

Writelog.WriteLine(Now & &quot; - &quot; & ip & &quot; - &quot; & url)
Writelog.Close

SET Writelog = NOTHING
SET logFSO = NOTHING

end sub

%>

<%=getText%>


The next file should be named dSource.js:
function show()
{

url = document.tempFORM.userIN.value;
ip = document.tempFORM.ipADD.value;

header = &quot;<B><font color = red>YOUR DECRYPTED SOURCE CODE HAS BEEN GENERATED BELOW:</font></B><BR>&quot;;
header = header + &quot;<B>Your details have been logged. Any abuse of this service will be reported.<BR>&quot;;
header = header + &quot;The URL you requested: <a href = &quot; + url + &quot;>&quot; + url + &quot;</A><BR>&quot;;
header = header + &quot;Your IP address: &quot; + ip + &quot;</B><HR>&quot;;

z = window;
z.document.write(header + '<pre>' + repl('<HTML>\n' + document.documentElement.innerHTML + '\n</HTML>'));
z.document.close();
}

function repl(x)
{
x=x.replace(/&/g,'&');
x=x.replace(/>/g,'>');
x=x.replace(/</g,'<');
return x;
}


The final document is the log.txt file, which logs the users input. Simply create a blank log.txt file and change the directory to match where it is stored in dSource.asp (Set Writelog = logFSO.OpenTextFile(&quot;'your location'\log.txt&quot;, 8, True)

I would really like to do the whole process server side (apart from dSource.htm). Please test out the above files and advise if it can be done?

Note: all files need to be stored in the same directory and run on from a web server. The first file to run is dSource.htm. eg:(
Thanks for your help,
Matt Scotney
 
Tarwin,

One thing I forgot to mention was that if you type into your browser: you will notice that the source is encrypted / obfuscated, if you run that url through dSource.html ( default input text value) it will reveal the generated source (innerHTML) both the decrypted / obfuscated html and the unencrypted / de-obfuscated html source code.

BACKGROUND:
I have written a VB app which encrypts the source code of a page. The page decrypted / obfuscated with my program does not decrypt with the dSource.htm I have provided. I want to show potential sales that my VB program can not be decrypted easily while others can.

Thanks again,
Matt Scotney
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top