Monday, July 25, 2016

get all html code (clone) and encode the data

some time you need to save some of html data on localStorage. that time we need to encode that data before saving. this code might be help you.

 var entityMap = {
            "&": "&",
            "<": "<",
            ">": ">",
            '"': '"',
            "'": ''',
            "/": '/'
        };

        function escapeHtml(string) {
            return String(string).replace(/[&<>"'\/]/g, function (s) {
                return entityMap[s];
            });
        }

           $clone = $('html').html();
           console.log("Encoded HTML is = "+escapeHtml($clone));

No comments:

Post a Comment