Use script as `

How to show literal javascript as part of a regular body in HTML?

I have the HTML below

<body> <p><font color="red">Use script as `<script>alert('123')</script>` - must be a number</p> </body> 

How to show it as is? I want to avoid deleting script tags and make sure the browser is not executing the script.

+4
source share
3 answers

Assuming you want to display this in a string, you need to avoid < and > with objects &lt; and &gt;

 Use script as `&lt;script&gt;alert('123')&lt;/script&gt;` - mu... 
+4
source

I installed an example:

http://jsfiddle.net/ZYKpk/1/

 <p><font color="red">Use script as `&#60;script&#62;alert('123')&#60;/script&#62;` - must be a number</p> 

To achieve this, you should avoid html tags.

0
source

Example here: http://jsfiddle.net/ZYKpk/3/

 Use script as: <pre> &lt;script> alert('123'); &lt;/script> </pre> Or use script as: <code> &lt;script> alert('123'); &lt;/script> </code> 
0
source

Source: https://habr.com/ru/post/1402223/


All Articles