javascript - Remove everything outside of body tags -


i have variable contains responsetext external html page:

textfromfile = myrequest.responsetext; 

how delete outside of body tags? can delete html tags in string (textfromfile) using regex before that, appreciate if me removing characters outside of body tags (in other words, keep strings/ words within body tags of html page).

----edited part----

the html file reading in is:

<html> <head> title </head> <body> <p> hello world! <br/> <a href = ”link.html”> click <b> here </b> </a> <br/> goodbye world! </p> </body> </html> 

when apply:

var doc = new domparser().parsefromstring(myrequest.responsetext, "text/html");             alert(doc.body.innerhtml); 

the response is:

title   <p> hello world! <br> <a href="”link.html”"> click <b> here </b> </a> <br> goodbye world! </p> 

which shouldn't case 'title' outside of body tags.

use dom parser parse html:

var doc = new domparser().parsefromstring(myrequest.responsetext, "text/html"); 

and use innerhtml (or outerhtml):

doc.body.innerhtml; 

var string = "<!doctype html><title>title</title><p>hello</p>",      doc = new domparser().parsefromstring(string, "text/html");  document.getelementbyid('inner').textcontent = doc.body.innerhtml;  document.getelementbyid('outer').textcontent = doc.body.outerhtml;
pre {    background: #ddd;    font-family: monospace;    padding: .5em;  }
the inner html of &lt;body&gt; is:  <pre id="inner"></pre>  outer html of &lt;body&gt; is:  <pre id="outer"></pre>


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -