Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load local javascript file in chrome for testing?

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?

like image 815
simple Avatar asked Dec 23 '13 17:12

simple


People also ask

How do I test locally in JavaScript?

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.

How do I run a local JavaScript file?

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.

How do I run a .js file in my browser?

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.


1 Answers

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> 
like image 97
picmate 涅 Avatar answered Sep 25 '22 21:09

picmate 涅