Commenting out code


I decided to break out a code suggestion you made in another thread because that trhead was getting quite long as is.

You suggested commenting out Javascript in news articles I was trying to save as a way to prevent them from breaking when I go back to view them.

You mentioned replacing things like this…

<script		<!-- script
</script>		<script -->

Because I have been away from coding for so long, this code confuses me.

I guess that <script is an opening tag for Javascript?

And I think that <!– is how you start an HTML comment, so <!-- script would supposedly beging an HTML comment, right?

I believe is a closing Javascript tag, right?

And I think that is a closing HTML comment?

I think I follow what you find & replace thinking does, but I’m a little lost on why you chose to replace with <script →

Could you or someone help to better understand this?

Hi, You are correct about the html comment marks. <!-- -->

I checked his post and he suggested:

a. find <script globally replace with <!-- script
b. find </script> globally replace with <script -->

The last bit may look like a typo, as meant to be </script -->, but I think it’s not a typo because browsers are smart and maybe regard it as an end tag nevertheless and mess up the code.

The goal was to disable the inline scripts and the a-b does that safely. It’s still easy to undo the edit if needed.

Hi Erik,

For the first find&replace, would this also work…

<script	<!--

And for the second find&replace, would this also work…

</script>	 -->

Depends of the rest in the tags. Why do the replace that way instead of what @John_Betong tried and suggested?

1 Like

Just trying to understand what he did and making sure there wasn’t a slightly simpler way, that’s all. :slight_smile:

1 Like

Sorry for being unclear, I should have linked to a definition of the html comment. :slight_smile:

Hi there CrazyCatCoder,

if it makes you happier you could use
find & replace like this…

<!-- <script 

…for this…


…and this…

/script> -->

…for this…



Hi Coothead! :slight_smile:

Your order is a little odd above! Did you mean this?

<script		<!-- <script
</script>	</script> -->


Based on reading that, it seems this should also work, no?

<script		<!-- 
</script>	-->

Maybe the both safest and easiest find-replace would be to simply replace all <script with <scrap and all </script with </scrap (or just omit the s in script or anything that’s easy to remember).

That would avoid all mishaps with eventual detached gt > signs in the original tags.

1 Like

Actually not, if you mind that the browser could interpret the tag ending > sign in the start tag for the script as the end of the comment.

Easy to miss, as I did above. :slight_smile:

Yes that is correct. :winky:


That sounds like a good idea. What do others think?

They probably think I should go to sleep already. :smile:

It’s not such a good idea (didn’t think straight), the tag becomes an unknown tag name that could mess up the whole page. :scream:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.