|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
HTML Code Killer
I'm hoping to devise a javascript that will remove an html comment. "Why" is not so much a concern as "how".
Another more experienced programmer presented some very interesting code that I'd like to build from. The html comment I'm trying to remove is in the <head> of my page and reads: Code:
<!-- </textarea> --> Code:
<!-- kill --><!-- </textarea> --><!-- kill --> Code:
function KillCode() {
if (document.getElementsByTagName) {
var head = document.getElementsByTagName('head')[0];
var headHTML = head.innerHTML;
var headHTMLPieces = headHTML.split('<!-- kill -->');
head.innerHTML = headHTMLPieces[0] + headHTMLPieces[2];
}
}
Last edited by robindean; 05-20-2007 at 08:10 PM. |
|
#2
|
||||
|
||||
|
I can somewhat answer your question only because I know your past situation. If you use this code, for instance (I'm using base instead of META refresh only because it's more convenient while testing):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-us">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<script type="text/javascript">document.write('<!-- <textarea rows="0" cols="0" style="width: 0px; height: 0px; display: none;">');</script>
<base href="http://www.w3.org/">
<!-- kill --><!-- </textarea> --><!-- kill -->
</head>
<body>
<p>Hello, <a href="123">World!</a></p>
</body>
</html>
Code:
<html lang="en-us"><head><title></title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<script type="text/javascript">document.write('<!-- <textarea rows="0" cols="0" style="width: 0px; height: 0px; display: none;">');</script><!-- <textarea rows="0" cols="0" style="width: 0px; height: 0px; display: none;">
<base href="http://www.w3.org/">
<!-- kill --><!--></head><body>--><!-- kill -->
<p>Hello, <a href="123">World!</a></p>
</body></html>
__________________
for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"')) {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n"; |
|
#3
|
|||
|
|||
|
I see, so we've got trouble as a result of the javascripts end result. The puzzle, once again, grows.
|
|
#4
|
||||
|
||||
|
Code:
function removeComments() {
var head=document.getElementsByTagName('head')[0];
var children=head.childNodes;
for(var i=0; i<children.length; i++) {
if(children[i].nodeType==8) {head.removeChild(children[i]);}
}
}
__________________
At least 98% of internet users' DNA is identical to that of chimpanzees Last edited by Fang; 05-21-2007 at 02:18 AM. |
|
#5
|
|||
|
|||
|
Thanks Fang!
However, I managed to devise a solution to my alternate thread which involved a different outcome. Regardless, this answer strongly applies others who might be interested in doing this. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|