简体   繁体   中英

Importing .js file into html using <script>

I've looked at different posts on StackOverflow but I can't seem to solve this problem despite following the suggestions. Any help would be appreciated.

I have the following HTML code in the file home.html in my frontend folder:

`<!DOCTYPE html>
  <html lang="en">
  <head>
  <title> Home Page </title>
   <meta charset="utf-8">
   <script src ="src/home.js"></script>
  </head> 
  </html>`

And I have a file home.js in the folder src that I'm trying to import. However, when I then run localhost I get the error:

The resource from “ http://localhost:3000/src/home.js ” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)

I've tried adding

app.use("/src", express.static(path.join(__dirname, "../src"))); app.use("/frontend", express.static(path.join(__dirname, "../frontend")));

to my server.js file but it doesn't help.

Thanks in advance!

添加“类型”属性,如下所示。

<script type="text/javascript" src="path-to-javascript-file.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM