mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
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
This commit is contained in:
parent
75b48e6a2b
commit
0e123509d5
@ -1,5 +1,4 @@
|
|||||||
import { jQuery } from "../core.js";
|
import { jQuery } from "../core.js";
|
||||||
import { document } from "../var/document.js";
|
|
||||||
import { rsingleTag } from "./var/rsingleTag.js";
|
import { rsingleTag } from "./var/rsingleTag.js";
|
||||||
import { buildFragment } from "../manipulation/buildFragment.js";
|
import { buildFragment } from "../manipulation/buildFragment.js";
|
||||||
import { isObviousHtml } from "./isObviousHtml.js";
|
import { isObviousHtml } from "./isObviousHtml.js";
|
||||||
@ -17,20 +16,14 @@ jQuery.parseHTML = function( data, context, keepScripts ) {
|
|||||||
context = false;
|
context = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var base, parsed, scripts;
|
var parsed, scripts;
|
||||||
|
|
||||||
if ( !context ) {
|
if ( !context ) {
|
||||||
|
|
||||||
// Stop scripts or inline event handlers from being executed immediately
|
// Stop scripts or inline event handlers from being executed immediately
|
||||||
// by using document.implementation
|
// by using DOMParser
|
||||||
context = document.implementation.createHTMLDocument( "" );
|
context = ( new window.DOMParser() )
|
||||||
|
.parseFromString( "", "text/html" );
|
||||||
// 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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed = rsingleTag.exec( data );
|
parsed = rsingleTag.exec( data );
|
||||||
|
Loading…
Reference in New Issue
Block a user