简体   繁体   中英

Disable or Replace Some HTML Tags

I have a online webpage. There has a code placed by default:-

<body><center><table border="0" width="100%"><tr><td valign="top" align="center"><div class="webpage_body" style="text-align: left;">

I am facing many issues with this code. It is placed after </head> tag. I want to disable or replace it via JavaScript or CSS. I've tried to replace it into an unknown HTML by javascript:-

var s="<center><table border="0" width="100%"><tr><td valign="top" align="center"><div class="webpage_body" style="text-align: left;">"; s = s.replace(/<center>/g, "<c>"); s = s.replace(/<table>/g,"<ta>"); s = s.replace(/<tr>/g,"<fr>"); alert(s);

But nothing happens to it. ( Edit: ) Also I can't replace the <table because it isn't <table> ! How can I do this?

You've got a typo in there. You're using " for the HTML string but inside of the HTML , you use " too. That will break it. Just try to use ' at the beginning and the end of the string.


This is how it looks if you are using a editor: 带有“

This if how it looks if you are wrap it with ' instead of " 以'代替“的字符串

The Boxes are there to visualize the strings.


Here's the working example:

 var s = '<center><table border="0" width="100%"><tr><td valign="top" align="center"><div class="webpage_body" style="text-align: left;">'; s = s.replace(/<center>/g, "<c>"); s = s.replace(/<table>/g, "<ta>"); s = s.replace(/<tr>/g, "<fr>"); alert(s); 

Just a little hint: In your example, <table> will never be replaced because your example has no <table> . Only <table .

You can do this with s.replace(/<table/g, "<ta"); or s.replace(/table/g, "ta"); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM