admin管理员组

文章数量:1023554

I am using that block of code and bring told by a code validator that this should be sanitized.

What is wrong with it and how can i sanitize it?

el1 = document.getElementById('quote'); //this is fine
el1.innerHTML = quoteNew; //this should be sanitized

I am using that block of code and bring told by a code validator that this should be sanitized.

What is wrong with it and how can i sanitize it?

el1 = document.getElementById('quote'); //this is fine
el1.innerHTML = quoteNew; //this should be sanitized
Share Improve this question asked May 16, 2017 at 23:22 scandalousscandalous 9125 gold badges15 silver badges25 bronze badges 4
  • 1 Where does quoteNew e from? – Ry- Commented May 16, 2017 at 23:24
  • 2 If it is supposed to be just text, then the safe way is el1.textContent = quoteNew; – Gabriele Petrioli Commented May 16, 2017 at 23:27
  • quoteNew is a string with some css added to it – scandalous Commented May 17, 2017 at 6:15
  • @GabyakaG.Petrioli : It works!. Please make an answer so that I can choose your answer as best answer. – scandalous Commented May 17, 2017 at 6:21
Add a ment  | 

1 Answer 1

Reset to default 5

If the contents of quoteNew are just text to display, then use the textContent property of the element.

 el1.textContent = quoteNew;

I am using that block of code and bring told by a code validator that this should be sanitized.

What is wrong with it and how can i sanitize it?

el1 = document.getElementById('quote'); //this is fine
el1.innerHTML = quoteNew; //this should be sanitized

I am using that block of code and bring told by a code validator that this should be sanitized.

What is wrong with it and how can i sanitize it?

el1 = document.getElementById('quote'); //this is fine
el1.innerHTML = quoteNew; //this should be sanitized
Share Improve this question asked May 16, 2017 at 23:22 scandalousscandalous 9125 gold badges15 silver badges25 bronze badges 4
  • 1 Where does quoteNew e from? – Ry- Commented May 16, 2017 at 23:24
  • 2 If it is supposed to be just text, then the safe way is el1.textContent = quoteNew; – Gabriele Petrioli Commented May 16, 2017 at 23:27
  • quoteNew is a string with some css added to it – scandalous Commented May 17, 2017 at 6:15
  • @GabyakaG.Petrioli : It works!. Please make an answer so that I can choose your answer as best answer. – scandalous Commented May 17, 2017 at 6:21
Add a ment  | 

1 Answer 1

Reset to default 5

If the contents of quoteNew are just text to display, then use the textContent property of the element.

 el1.textContent = quoteNew;

本文标签: Sanitize innerHTML in javascriptStack Overflow