javascript - External JS file causing my webpage to appear blank - Stack Overflow

I'm making a browser-based clone of an old strategy game called Diplomacy. This is what I've

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
Add a ment  | 

2 Answers 2

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>

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信