“JS Escape Html” Respostas de código

JavaScript Escape HTML

function escapeHtml(str) {
    return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}
Grepper

JS Escape Html

function escapeHtml(text) {
  return text
      .replace(/&/g, "&")
      .replace(/</g, "<")
      .replace(/>/g, ">")
      .replace(/"/g, """)
      .replace(/'/g, "'");
}
Enrybi

função de escape html javascript

function escapeHTML(text) {  
    var replacements= {"<": "&lt;", ">": "&gt;","&": "&amp;", """: "&quot;"};                      
    return text.replace(/[<>&"]/g, function(character) {  
        return replacements[character];  
    }); 
}
Creepy Gábor

javascript escape html string

//escaping HTML with jquery
var dangerousHTML = "<script>alert('Badabing Baby!');</script>";
$("#myElementID").text(dangerousHTML); //.text() function will escape and display text


//Alternatively, here is plain Javascript escape function
function escapeHtml(str) {
    return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
Grepper

Respostas semelhantes a “JS Escape Html”

Perguntas semelhantes a “JS Escape Html”

Mais respostas relacionadas para “JS Escape Html” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código