Skip to content

Instantly share code, notes, and snippets.

@andresgallo
Last active August 7, 2024 15:08
Show Gist options
  • Save andresgallo/5ad313b4d74b14c1466a985d28823a87 to your computer and use it in GitHub Desktop.
Save andresgallo/5ad313b4d74b14c1466a985d28823a87 to your computer and use it in GitHub Desktop.
Fetch
const url = this.getAttribute('data-url')
fetch(url)
.then(function(response) {
return response.text()
})
.then(function(html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
console.log('HEREEEE', doc);
// this.innerHTML = doc.documentElement.innerHTML
})
.catch(function(err) {
console.log('Failed to fetch page: ', err);
});
((url) => {
fetch(url)
.then(function(response) {
return response.text()
})
.then(function(html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
console.log('HEREEEE', doc);
// this.innerHTML = doc.documentElement.innerHTML
})
.catch(function(err) {
console.log('Failed to fetch page: ', err);
});
})('somepage.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment