mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 03:14:59 -05:00
Core: set the base href of the context in parseHTML
Fixes gh-2965 Close gh-3022
This commit is contained in:
@@ -21,14 +21,28 @@ jQuery.parseHTML = function( data, context, keepScripts ) {
|
||||
context = false;
|
||||
}
|
||||
|
||||
// Stop scripts or inline event handlers from being executed immediately
|
||||
// by using document.implementation
|
||||
context = context || ( support.createHTMLDocument ?
|
||||
document.implementation.createHTMLDocument( "" ) :
|
||||
document );
|
||||
var base, parsed, scripts;
|
||||
|
||||
var parsed = rsingleTag.exec( data ),
|
||||
scripts = !keepScripts && [];
|
||||
if ( !context ) {
|
||||
|
||||
// Stop scripts or inline event handlers from being executed immediately
|
||||
// by using document.implementation
|
||||
if ( support.createHTMLDocument ) {
|
||||
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 );
|
||||
} else {
|
||||
context = document;
|
||||
}
|
||||
}
|
||||
|
||||
parsed = rsingleTag.exec( data );
|
||||
scripts = !keepScripts && [];
|
||||
|
||||
// Single tag
|
||||
if ( parsed ) {
|
||||
|
||||
Reference in New Issue
Block a user