Evan Troxell
Evan Troxell

Reputation: 1

Running javascript files without using modules

I'm working on a project in HTML and have been running JavaScript modules from it. However, I'm encountering the error in my browser that CORS is blocking a local file.

I did some research and I heard that regular .js files may not be blocked in this way, and that .mjs files were the source of this problem. However, I cannot find how to import and export code between .js files in a way similar to modules, if it is possible at all. Is there a way to do this? Or is there another solution to files being blocked by CORS in a browser? I really would prefer not to have to download a local server and run files as HTTP, I want to just be able to execute it without any extra steps in a browser.

This is a side note and might not need to be answered, but how do I retrieve text from a text or JSON file without using modules? If the answer is that I should switch to regular .js files, then how should I go about this?

Upvotes: 0

Views: 112

Answers (0)

Related Questions