How can I capture the HTML from a link in JavaScript? Alternatively, for a more conversational tone: W

20 Replies, 1416 Views

Hey! If you're trying to capture the html from a link in javascript, `fetch()` is the way to go, but you gotta handle the response properly. Try this:

```javascript
fetch('your-url-here')
.then(response => response.text())
.then(html => console.log(html))
.catch(error => console.error('Oops:', error));
```

If it’s failing, yeah, probably CORS. Try a proxy like [CORS Anywhere](https://cors-anywhere.herokuapp.com/) for testing.

Messages In This Thread



Users browsing this thread: 1 Guest(s)