Monday, 15 March 2010

javascript - Remove HTML tags and entites from string coming from server -



javascript - Remove HTML tags and entites from string coming from server -

in app receive html text: since app can't display (interpret) html, need remove html tag , entity string receive server.

i tried following, 1 removes html tags not entities (eg. &bnsp;):

stringfromserver.replace(/(<([^>]+)>)/ig,"");

any help appreciated.

disclaimer: need pure javascript solution (no jquery, underscore, etc.).

[update] i'm reading answers , forgot mention i'm using javascript environment not web page, have no dom.

you can seek this:

var placeholder = document.createelement('div'); placeholder.innerhtml = stringfromserver; var thetext = placeholder.innertext;

.innertext grabs text content element.

however, since appears don't have access dom manipulation @ all, you're going have utilize kind of html parser, these: https://www.npmjs.org/package/htmlparser http://ejohn.org/blog/pure-javascript-html-parser/

javascript html regex string

No comments:

Post a Comment