‘Uncaught ReferenceError: window is not defined’ in vanilla javascript

I have come across this reference error (Uncaught ReferenceError: window is not defined) when trying to build a weather app using just html/css/js. I have looked up and tried several solutions from here and elsewhere but nothing seems to solve my issue. Any help would be appreciated.

html

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./styles.css">
    <title>Weather</title>
</head>
<body>
  <div class= "location">
  <h1 class=location-timezone>Timezone</h1>
  <p>icon</p>
</div>
<div class="temperature">
    <div class="degree-section">
    <h2 class="temperature-degree">34</h2>
    <span>F</span>
</div>
    <div class="temperature-description">It's cold
    </div>
</div>
    
    <script>src="app.js"</script>
</body>
</html>

js

    window.addEventListener("load", () => {
    let long;
    let lat;

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(position => {
            console.log(position);
        });
    } else {
        h1.textcontent = "Please allow permission."
        
    }
});


Read more here: https://stackoverflow.com/questions/65711496/uncaught-referenceerror-window-is-not-defined-in-vanilla-javascript

Content Attribution

This content was originally published by Mamdlv at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: