スキップしてメイン コンテンツに移動

投稿

ラベル(online tool)が付いた投稿を表示しています

Escape Html by Javascript

When I copy and paste some code snippet on this blog, I have to escape some special characters for example "<", ">", etc. I googled how to escape html special characters by javascript and found escaping-html-strings-with-jquery . Based on the answer, I created simple html escape tool below. copy & paste text in this text area, then html escaped text will be output text area below. The whole javascript code is below! <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> $(function(){ $("#src_html").keyup(function(){ $("#dest_html").val(escapeHtml($("#src_html").val())); }); var entityMap = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': '&quot;', "'": '&#39;', "/": '&#x2F;' }; func...