admin管理员组文章数量:1405339
I'm making a browser-based clone of an old strategy game called Diplomacy. This is what I've got so far:
<html>
<head>
<title>Diplomacy</title>
<script type="text/javascript" src="game.js" />
</head>
<body>
<canvas id="canvas" width="750" height="750" style="border: 3px solid black; background:url('DiplomacyMap.png');">
Your browser does not support Canvas.
</canvas>
</body>
</html>
What does it look like in-browser? A blank page. However, if I remove the link to the external JS file in the head (game.js), it shows up no problem. This doesn't appear to have to do with the contents of the JS file, as even if I delete them or ment them all out, the problem persists. It seems to be to do with the mere presence of the element.
If I replace the <script src="file.js">
element with an embedded <script> ...code... </script>
, the page works fine.
So... what's going on?
PART 2:
<script type="text/javascript">
colorProvince(PARIS, FRANCE);
</script>
Although the colorProvince function and the PARIS and FRANCE constants are all defined in game.js, this function isn't being called (as verified by a simple alert() in the colorProvince function). This doesn't do anything, either:
<script type="text/javascript">
alert(colorProvince);
</script>
I'm making a browser-based clone of an old strategy game called Diplomacy. This is what I've got so far:
<html>
<head>
<title>Diplomacy</title>
<script type="text/javascript" src="game.js" />
</head>
<body>
<canvas id="canvas" width="750" height="750" style="border: 3px solid black; background:url('DiplomacyMap.png');">
Your browser does not support Canvas.
</canvas>
</body>
</html>
What does it look like in-browser? A blank page. However, if I remove the link to the external JS file in the head (game.js), it shows up no problem. This doesn't appear to have to do with the contents of the JS file, as even if I delete them or ment them all out, the problem persists. It seems to be to do with the mere presence of the element.
If I replace the <script src="file.js">
element with an embedded <script> ...code... </script>
, the page works fine.
So... what's going on?
PART 2:
<script type="text/javascript">
colorProvince(PARIS, FRANCE);
</script>
Although the colorProvince function and the PARIS and FRANCE constants are all defined in game.js, this function isn't being called (as verified by a simple alert() in the colorProvince function). This doesn't do anything, either:
<script type="text/javascript">
alert(colorProvince);
</script>
Share
Improve this question
edited Jun 27, 2011 at 17:26
bpeterson76
12.9k6 gold badges50 silver badges82 bronze badges
asked Jun 27, 2011 at 16:44
Jack MJack M
6,1757 gold badges53 silver badges77 bronze badges
1
-
The 2nd part really should be a separate question. Also without seeing how
game.js
is defined it's going to be difficult to answer. – David Ly Commented Jun 27, 2011 at 17:27
2 Answers
Reset to default 9<script type="text/javascript" src="game.js" />
needs to be
<script type="text/javascript" src="game.js"></script>
and in game.js there is an extra semicolon in colorProvince()
. replace it with this:
function colorProvince(province, nation){
alert(5);
for (var i = 0; i < province.getRectangles().length; i++)
{
//colorRect(rect, "red");
}
}
<script>
tags can not be self closed. They have to have an ending tag, otherwise most browsers will choke.
Instead of <script />
Use <script></script>
本文标签: javascriptExternal JS file causing my webpage to appear blankStack Overflow
版权声明:本文标题:javascript - External JS file causing my webpage to appear blank - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744896534a2631098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论