Access local Javascript file from a local HTML file - Stack Overflow

There are many questions similar to this but none of them have been able to help me.I am new to HTML an

There are many questions similar to this but none of them have been able to help me.

I am new to HTML and JS development. I have a simple HTML file that is trying to access a simple Javascript file.

HTML:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
document.write("In HTML")

</script>

<script type="text/javascript" src=./asdf.js></script>
</head>
<body>
<div id="map3d" style="height:400px;width:600px;border:1px solid red"></div>
</body>

The Javascript file is named asdf and exists in the same location as the HTML. I have tried the full file path, just the name "asdf.js" and several other options I can't recall.

My .js file reads thusly:

<script>
document.write("In JS")
</script>

The "In JS" doesn't appear. What am I doing wrong?

There are many questions similar to this but none of them have been able to help me.

I am new to HTML and JS development. I have a simple HTML file that is trying to access a simple Javascript file.

HTML:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample</title>
<script type="text/javascript" src="https://www.google./jsapi"></script>
<script type="text/javascript">
document.write("In HTML")

</script>

<script type="text/javascript" src=./asdf.js></script>
</head>
<body>
<div id="map3d" style="height:400px;width:600px;border:1px solid red"></div>
</body>

The Javascript file is named asdf and exists in the same location as the HTML. I have tried the full file path, just the name "asdf.js" and several other options I can't recall.

My .js file reads thusly:

<script>
document.write("In JS")
</script>

The "In JS" doesn't appear. What am I doing wrong?

Share Improve this question asked Apr 18, 2013 at 20:30 Kyle WrightKyle Wright 5202 gold badges10 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

External scripts do not require <script> and </script>. Write external scripts as if you were writing in between the tags.

In your JS file remove the <script> and </script> tags. They are for using JavaScript embedded within HTML, not for external file.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744691960a4588263.html

相关推荐

  • Access local Javascript file from a local HTML file - Stack Overflow

    There are many questions similar to this but none of them have been able to help me.I am new to HTML an

    23小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信