diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2024-12-11 00:38:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 00:38:27 +0100 |
commit | 0e123509d529456ddf130abb97e6266b53f62c50 (patch) | |
tree | a2beb014bc800c59c08c37119aa8f591972adf03 | |
parent | 75b48e6a2bff1258ca4d85ab7887e78772a67a69 (diff) | |
download | jquery-0e123509d529456ddf130abb97e6266b53f62c50.tar.gz jquery-0e123509d529456ddf130abb97e6266b53f62c50.zip |
Core: Switch `$.parseHTML` from `document.implementation` to `DOMParser`
Using a document created via:
```js
document.implementation.createHTMLDocument( "" )
```
was needed in IE 9 which doesn't support `DOMParser#parseFromString` for
`text/html`. We can switch to:
```js
( new window.DOMParser() ) .parseFromString( "", "text/html" )
```
now, saving some bytes.
Closes gh-5572
-rw-r--r-- | src/core/parseHTML.js | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index 6de02e8b6..936ac5788 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -1,5 +1,4 @@ import { jQuery } from "../core.js"; -import { document } from "../var/document.js"; import { rsingleTag } from "./var/rsingleTag.js"; import { buildFragment } from "../manipulation/buildFragment.js"; import { isObviousHtml } from "./isObviousHtml.js"; @@ -17,20 +16,14 @@ jQuery.parseHTML = function( data, context, keepScripts ) { context = false; } - var base, parsed, scripts; + var parsed, scripts; if ( !context ) { // Stop scripts or inline event handlers from being executed immediately - // by using document.implementation - context = document.implementation.createHTMLDocument( "" ); - - // Set the base href for the created document - // so any parsed elements with URLs - // are based on the document's URL (gh-2965) - base = context.createElement( "base" ); - base.href = document.location.href; - context.head.appendChild( base ); + // by using DOMParser + context = ( new window.DOMParser() ) + .parseFromString( "", "text/html" ); } parsed = rsingleTag.exec( data ); |