I'm trying to fetch an HTML data (which I parsed from string because the javascript files linked to it doesn't work) from a url, then load the response into document. However, when I log the response in the console, I get the html content but it displays [object HTMLDocument] when I load the document.
Here is my code -
fetch(url)
.then(res => res.text())
.then(data => {
let parsedRes = (new window.DOMParser()).parseFromString(data, "text/html")
processData(parsedRes, url)
});
function processData(response, urlPath){
console.log(response)
document.querySelector("html").innerHTML = response;
window.history.pushState({}, "", urlPath);
};
How can this be achieved?
response
is a document object, innerHTML expects a string. You could use the inner html of the response
document...
fetch(`data:text/html;,<html><head>\
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.