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

removing javascript from a HTML file dynamically

I am designing a forum system, and I would like to know if there is a script
somewhere that can parse an HTML response, and remove javascript.

I would like to do this so that I don't have hackers attempting to take over
the client's browser. I have my code to the point that it will remove all
script tags, and anything between them, but I have no idea how to remove the
"on-" events (for example, omouseout, onmouseover, etc...)

Also, I would like to remove any references to the position attribute of an
element's style. This is proving to be difficult, because there are various
ways it could be embedded into the script. For example,

<div style="position: absolute; left: 0px; top: 0px; height: 100000; width:
100000"></div>

renders the same as:

<div style="#$&%&@*%position: absolute; left: 0px; top: 0px; height: 100000;
width: 100000"></div>

and renders the same as:

<div style="position#$&%&@*%: absolute; left: 0px; top: 0px; height: 100000;
width: 100000"></div>

which makes it kinda hard to parse out the position attribute, which would
force me to filter out the word "position" from the entire document, which
is not acceptable.

Got any suggestions?
Jul 19 '05 #1
3 2194
Already figured it out...Thanks anyways.

"ASP.Confused" <anonymous@> wrote in message
news:uJ**************@TK2MSFTNGP09.phx.gbl...
I am designing a forum system, and I would like to know if there is a script somewhere that can parse an HTML response, and remove javascript.

I would like to do this so that I don't have hackers attempting to take over the client's browser. I have my code to the point that it will remove all
script tags, and anything between them, but I have no idea how to remove the "on-" events (for example, omouseout, onmouseover, etc...)

Also, I would like to remove any references to the position attribute of an element's style. This is proving to be difficult, because there are various ways it could be embedded into the script. For example,

<div style="position: absolute; left: 0px; top: 0px; height: 100000; width: 100000"></div>

renders the same as:

<div style="#$&%&@*%position: absolute; left: 0px; top: 0px; height: 100000; width: 100000"></div>

and renders the same as:

<div style="position#$&%&@*%: absolute; left: 0px; top: 0px; height: 100000; width: 100000"></div>

which makes it kinda hard to parse out the position attribute, which would
force me to filter out the word "position" from the entire document, which
is not acceptable.

Got any suggestions?

Jul 19 '05 #2
And of course to disable all HTML tags and JavaScript to and perhaps
later just show the code as text:

varFld = Server.HTMLEncode(varFld)

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
Classic ASP Design Tips, ASP Web Database Demo, ASP Bar Chart Tool...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3
Thanks! I'm actually designing a rich text forum, so that snippet of code
won't help me out immediately. Also, no one will be using the forum to post
code, but I will look into adding that at a later date.

"Bullschmidt" <pa**@bullschmidt.com-nospam> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
And of course to disable all HTML tags and JavaScript to and perhaps
later just show the code as text:

varFld = Server.HTMLEncode(varFld)

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
Classic ASP Design Tips, ASP Web Database Demo, ASP Bar Chart Tool...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4

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

Similar topics

9
by: quikquic | last post by:
Suppose I download a html file with javascript in it, for example, <html> <body> <script language="JavaScript"> document.write("Hello"); </script> </body> </html>
6
by: KKramsch | last post by:
OK, here's the scenario: I have a CGI script that generates a page with frames (BTW, I'm not crazy about frames, but in this case the decision to use them is out of my hands). In a typical...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
5
by: Peter | last post by:
I have the following code that executes JavaScript, is there a way I can put the same JavaScript code in it's own file and execute the code in that file instead of having this JavaScript code in my...
1
by: Sin Jeong-hun | last post by:
Is it possible to modify the HTML or the script of a WebBrowser control in DocumentCompleted event? I tried to modify it but that caused DocumentCompleted again so the program fell in an endless...
6
by: newholborn | last post by:
Hi everyone. I have some questions, which should be rather easy to reply, but as I am working on PHP, JavaScript, XML, CSS, Photoshop and other stuff at the same time, my head, which is about to...
9
by: mevryck | last post by:
Greetings I have a huge Javascript with inclusion of external scripts and all. I got this by doing a XSLT . Now I have the contents in a Javascript variable, but I'm not able to update the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.