I am tring to display website from wikipedia on my site but i have problem with cors. Please can somone help me? I tried so many things but nothing work for me.
error:
Access to fetch at 'https://en.wikipedia.org/w/index.php?title=elon_musk&action=render' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="content"></div>
</body>
<script>
contentUrl = 'https://en.wikipedia.org/w/index.php?title='
afterContentUrl = '&action=render'
title="elon_musk"
let url = contentUrl + title + afterContentUrl
fetch(url)
.then(function (response) { return response.text(); })
.then((data) => {
console.log(data)
document.getElementById('content').innerHTML = data
})
</script>
</html>
https://www.mediawiki.org/wiki/API:Main_page
Thanks:)