What are the ways which can be used to display [in html] a code segment involving script tag & at the same time preventing browser execution of that script code?
Encode all of the
|
|||||||||
|
you will need to escape special html related chars like this:
for a full list see: http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php |
||||
|
Encode all HTML entities ( < , > , & etc ) and wrap everything in pre tags to keep your formatting.
A handy converter: http://www.rishida.net/tools/conversion/ |
|||
|
Back in the days of HTML2, there were the
And it would show the tags as content, rather than interpret them as the start and end of elements (you couldn't do However, having this capability actually caused far more problems than they helped with, for both browser writers and for web authors. Hence, they were deprecated in HTML3.2 (or arguably HTML3 but that wasn't the only argument to HTML3 - another was just what document with "HTML3" on it was the one that counted...), and removed with HTML4. Hence, the only thing to do is to escape it.
That done, you can render it more prettily than |
||||
|
To be completely honest, I'm not sure if this is a great way to do this, so if it's not, I hope someone will tell me. If you don't feel like running your code through a converter, you can use this jQuery function to display the
|
|||
|