Custom JavaScript string operation protocol

From , 4 Years ago, written in JavaScript, viewed 55 times.
URL https://pastebin.vip/view/ff42b03a
  1. String.prototype.stripslashes = function(){
  2.     return this.replace(/<.*?>/g, '');
  3. };
  4.  
  5. String.prototype.htmlspecialchars = function(){
  6.     var str = this.replace(/&/g, '&');
  7.     str = str.replace(/</g, '<');
  8.     str = str.replace(/>/g, '>');
  9.     str = str.replace(/"/g, '"');
  10.     return str;
  11. };
  12.  
  13. //使用范例:
  14. var str = '<b>my personal website:</b> ';
  15. str += '<a href="http://www.jonasjohn.de/">jonasjohn.de</a>';
  16.  
  17. document.write("Original string (html): '" + str + "'<br/><br/>");
  18.  
  19. var str_no_html = str.stripslashes();
  20. document.write("- String without HTML tags: '" + str_no_html + "'<br/>");
  21.  
  22. var str_hsc = str.htmlspecialchars();
  23. document.write("- String with converted HTML tags: '" + str_hsc + "'");
  24. //javascript/2098

Reply to "Custom JavaScript string operation protocol"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website