jquery-pjax icon indicating copy to clipboard operation
jquery-pjax copied to clipboard

avoid lossing body when parsing html

Open layerssss opened this issue 12 years ago • 3 comments

  • as http://api.jquery.com/jQuery/#jQuery2 stats, the parsing process may strip body element, and return children of body instead of body. And this happens in most modern browsers (Chrome / Firefox latest releases).
When passing in complex HTML, some browsers may not generate a DOM that
exactly replicates the HTML source provided. As mentioned, jQuery uses
the browser"s .innerHTML property to parse the passed HTML and insert
it into the current document. During this process, some browsers filter
out certain elements such as  <html>,  <title>, or  <head> elements. As
a result, the elements inserted may not be representative of the
original string passed.
  • Also fixed the corresponding unit test.

layerssss avatar Oct 06 '13 04:10 layerssss

Why do you need the body?

staabm avatar Oct 06 '13 12:10 staabm

hi @staabm , because parseHTML's expected behaviour is to convent an HTML string into an element, not stripping the container element . In other way, not to get innerHtml, but the outterHtml. Stripping the container element (parent), will be done later ( https://github.com/layerssss/jquery-pjax/blob/48c17bb1846b4ebae6d1d4b36777998129737248/jquery.pjax.js#L651 ).

layerssss avatar Oct 07 '13 02:10 layerssss

Interesting. I'm not sure about this implementation but I need to investigate that original claim about losing the <body> element.

mislav avatar Oct 14 '14 16:10 mislav