I am trying to test some JavaScript on my local computer using the Chrome browser but Chrome will not load local resources. Is there an easy work around for this?
Or you can try CTRL + SHIFT + I which will open the tools in Chrome and Firefox. Within your browser's developer tools there is a tab called the Console. You can use this to run small snippets of JavaScript code.
You can Run your JavaScript File from your Terminal only if you have installed NodeJs runtime. If you have Installed it then Simply open the terminal and type “node FileName. js”. If you don't have NodeJs runtime environment then go to NodeJs Runtime Environment Download and Download it.
To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a . js extension) and then reference that file inside the HTML document using an empty script element with a src attribute.
If you are trying to just test the functionality of your JavaScript file: create a blank HTML file, add a link to your JS file as you would normally load a JS file from HTML, and open the HTML file in Chrome. Go to the JavaScript console. You'll be able to interact with the functionality of your JS code as usual. You wouldn't need to set up a server for this. If still not clear, here's an example:
<html> <head> <script type = "text/javascript" src = "path/to/your/jsfile"></script> </head> </html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With