Browse Source

fixed meta[charset] tag appending when the head tag is empty

Gildas 7 năm trước cách đây
mục cha
commit
83cfe4f2de
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      lib/single-file/single-file-core.js

+ 5 - 1
lib/single-file/single-file-core.js

@@ -462,7 +462,11 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			});
 			const metaElement = this.doc.createElement("meta");
 			metaElement.setAttribute("charset", "utf-8");
-			this.doc.head.insertBefore(metaElement, this.doc.head.firstElementChild);
+			if (this.doc.head.firstChild) {
+				this.doc.head.insertBefore(metaElement, this.doc.head.firstChild);
+			} else {
+				this.doc.head.appendChild(metaElement);
+			}
 		}
 
 		insertFaviconLink() {