I try to 'transfer' a variable from one js file to another.
I already tried to use import/export however it didn't work.
test1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=<device-width>, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<h1 class="sentence">hey guys</h1>
</div>
<script src="test1.js" type="module"></script>
</body>
</html>
test1.js
let greeting=document.querySelector('.sentence').innerHTML;
console.log(greeting);
test2.js
$.getScript('test1.js',function(){
console.log(greeting);
})
the error messages i get are: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///Users/michalislazaris/Desktop/test.js. (Reason: CORS request not http). and: Module source URI is not allowed in this document: “file:///Users/michalislazaris/Desktop/test.js”.