Sfoglia il codice sorgente

add base tag to the doc to set the base URI

Gildas 7 anni fa
parent
commit
7f68e228cc
1 ha cambiato i file con 4 aggiunte e 1 eliminazioni
  1. 4 1
      lib/single-file/single-file-browser.js

+ 4 - 1
lib/single-file/single-file-browser.js

@@ -70,8 +70,11 @@ this.SingleFile = (() => {
 	// DOM
 	// ---
 	class DOM {
-		static create(pageContent/*, url*/) {
+		static create(pageContent, baseURI) {
 			const doc = (new DOMParser()).parseFromString(pageContent, "text/html");
+			const baseElement = doc.createElement("base");
+			baseElement.href = baseURI;
+			doc.head.insertBefore(baseElement, doc.head.firstChild);
 			return {
 				DOMParser,
 				getComputedStyle,