As far as I know, websites that don’t have Access-Control-Allow-Origin
cannot be fetched using XMLHTTPRequest
from client side so this problem can be solved only from server side by adding *
to Access-Control-Allow-Origin
in the header section.
let url = 'https://tv.jordkris.com';
fetch(url).then(res => res.text())
.then((text) => {
var parser = new DOMParser();
var html = parser.parseFromString(text, "text/html");
var target = document.getElementById('target');
target.innerHTML = text;
})
.catch(err => console.error(err.message));
<div id="target"></div>
However, recently I came across a website that can perform CORS unblocking of a URL.
let url = 'https://corsproxy.io/?' + encodeURIComponent('https://tv.jordkris.com');
fetch(url).then(res => res.text())
.then((text) => {
var parser = new DOMParser();
var html = parser.parseFromString(text, "text/html");
var target = document.getElementById('target');
target.innerHTML = text;
})
.catch(err => console.error(err.message));
<div id="target"></div>
How does the website work so that it can unblock CORS from the client side?