Calling javascript file from html file doesn't work at all

177 views Asked by At

Running this simple code where javascript line is placed under Script tags displays the desired alert message

<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html>
<body>
<script type="text/javascript" >
alert('Hello World!');
</script>

</body>
</html>

But when I try to use an external .js file instead, I don't see it working at all. I tried surfing for solutions but nothing helped. I'm relatively new to scripting, so simple explanations are welcome. Thanks.

Html file placed at C:\UC

<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html>
<body>
<script type="text/javascript" src="../myTry.js" >
</script>
</body>
</html>

myTry.js placed inside C: has the following one line

alert('Hello World!');

I want this to work on IE 11

1

There are 1 answers

2
Greenhorn On

Change the path in src="../myTry.js". Suppose you have saved myTry.js file in c:\UC\myTry.js mention the path as <script type="text/javascript" src="c:\UC\myTry.js">.. I tried it, it's working for me.