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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744896535a4599730.html
评论列表(0条)