Results 1 to 2 of 2

Thread: Useful Prototype: htmlEntities()

  1. #1
    Join Date
    Jul 2008
    Posts
    40
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Useful Prototype: htmlEntities()

    This method escapes all &, <, and > symbols in the string, making it safe to display the string on a web page without fear that it will be treated as HTML.
    Code:
    <html> <head> <title>Strings</title> </head> <body>
    <script type="text/javascript"> String.prototype.htmlEntities = function () { return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace (/>/g,'&gt;'); }; var tmp = '<html><head></head>'; var safe= tmp.htmlEntities(); document.write(safe); </script>
    <p> This is the other way around, showing html tags' by simply using the "&lt;code&gt;&lt;/code&gt;" tags. <code>&lt;p&gt; some example of common tag's and p tags' is one of them&lt;/p&gt;</code>
    </body></html>
    Last edited by rainarts; 07-26-2008 at 06:11 PM.

  2. #2
    Join Date
    Aug 2004
    Posts
    9,878
    Thanks
    3
    Thanked 962 Times in 951 Posts
    Blog Entries
    15

    Default

    You'll want to format your code using the CODE tag, just for an easier read.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •