remove html comment?
|
|
I use a site that has invalid comments like this <!-----------blah-------> instead of <!-- blah --> firefox wont display the page properly. Opera and IE will. How can I write a script to remove/change those extra ----'s ? Seems like all code I write ignores comment sections. I tried this: (function() {
replacements = {
}; regex = {};
textnodes = document.evaluate( "//body//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
})(); |
|
|
You should contact them and tell them that you cant see the page properly because of that. They will mostlikely fix it theirselves. |
|
|
They won't. I need to adapt on my own. the official policy is IE only |
|
|
Well.. firstly On your code above, Firefox doesn't store the comment markup in the DOM, only it's contents, so you'd really need to do some kind of regEx replacement on |
|
|
I cant post the site, as its a secure login thing. the exact comments are:
each of these are basically commenting out whole sections of code, as firefox is reading the next two dashes as another comment. I am new to greasemonkey, and have no idea on how to use innerHTML - can you assist? |
|
|
Well, these comments are valid (as lucideer have mentioned) and can not comment out anything. Try yourself if you don't believe us. visible text 1<br><!-----------------------------------BEGIN SECTION I------------------------------------->visible text 2<br><!-----------------------------------END SECTION I------------------------------------->visible text 3<br><!-----------------------------------BEGIN SECTION VI------------------------------------>visible text 4<br><!-----------------------------------END SECTION VI------------------------------------->visible text 5 The issue must be somewhere else, and nobody could tell where unless you provide us access to that page in some way. PS
That's wrong, you can access comments in DOM, as DOM Inspector clearly shows. |
|
|
@Mikado
Edit No wonder it returns undefined. There is no outerHTML in Firefox... oh well. Either way, you get my point.. |
|
|
so could I get an example of code to remove those 4 lines entirely? I know they are the cause, b/c if I view source in firefox, the syntax highlighting comments everything out after that comment line |
|
|
I've copied and pasted those lines into random pages and put them in Firefox. No effect on any of them. What I'm guessing is happening, is the code before or after them is effecting the rendering in some way that simply makes it appear as though it's those comments. If you can't tell us the page, maybe you could try posting what's immediately above and below those comments.
var comments='<!-----------------------------------BEGIN SECTION I-------------------------------------><!-----------------------------------END SECTION I-------------------------------------><!-----------------------------------BEGIN SECTION VI------------------------------------><!-----------------------------------END SECTION VI------------------------------------->'; document.body.innerHTML=document.body.innerHTML.replace(comments,''); That would remove the comments, but as I said I doubt it's your problem. |
|
|
that did it lucideer, thanks |
