A simple way to test some javascript
Not too long ago I set up an entire Django app just for testing out my JavaScript interactions.
Just this morning I realized I didn't have to do any of that.
Simply create a folder, ( I did it on my desktop directory)
and put your html, and referenced javascript in the same folder.
To run the html file, all you have to do is double click it, The computer will run the HTML file through your default internet browser.
As long as your path to the javascript file is correct in your HTML <script> tag that is located in the header, your javascript should run. You can also change code and refresh the page on demand.
Why I didn't know this sooner is kinda irritating. So if your looking for a simple way to do this, and stumble across my blog post, maybe this is for you.
Example code below.
--May the spam be ever in your flavor --
<!-- The HTML -->
<!DOCTYPE html>
<html>
<head>
<title> will it work?</title>
<script type="text/javascript" src="/home/nellie/Desktop/browser test/index_1.js"></script>
<!-- If the location of the javascript file is incorrect it will not work -->
</head>
<!-- #91cac5 == greyish teal-->
<body onload="test_body_color('#91cac5')">
<h1> This is the browser opened page </h1>
<p id="first_paragraph"> This is the first paragraph</p>
</body>
</html>
// ----- JavaScript file ----
//javascript for browser test
function test_body_color(color){
var x = document.body.style;
x.backgroundColor = color;
alert("test_body_color function has been executed.")
}
Just this morning I realized I didn't have to do any of that.
Simply create a folder, ( I did it on my desktop directory)
and put your html, and referenced javascript in the same folder.
To run the html file, all you have to do is double click it, The computer will run the HTML file through your default internet browser.
As long as your path to the javascript file is correct in your HTML <script> tag that is located in the header, your javascript should run. You can also change code and refresh the page on demand.
Why I didn't know this sooner is kinda irritating. So if your looking for a simple way to do this, and stumble across my blog post, maybe this is for you.
Example code below.
--May the spam be ever in your flavor --
<!-- The HTML -->
<!DOCTYPE html>
<html>
<head>
<title> will it work?</title>
<script type="text/javascript" src="/home/nellie/Desktop/browser test/index_1.js"></script>
<!-- If the location of the javascript file is incorrect it will not work -->
</head>
<!-- #91cac5 == greyish teal-->
<body onload="test_body_color('#91cac5')">
<h1> This is the browser opened page </h1>
<p id="first_paragraph"> This is the first paragraph</p>
</body>
</html>
// ----- JavaScript file ----
//javascript for browser test
function test_body_color(color){
var x = document.body.style;
x.backgroundColor = color;
alert("test_body_color function has been executed.")
}
Comments
Post a Comment