Java script
Within a myShop custom-layout page a script tag can be used to include custom javascript functions or a reference to a javascript file. However, there are some rules which should be followed when doing so.
- Including a javascript file through a
<script language="javascript" src="http://www.mijnwinkel.nl/script/somescript.js"></script>
may not be done within the<body>
element of the page. This should be done within the<head>
element instead. – see example one
- There are two ways to include comments in the code – with two forward slashes
//
-, inline and across multiple lines – starting with/*
and ending with*/
. Only the second method can be used within a myShop custom-layout. – see second example - Each statement within a javascript function may be closed with a semicolon –
;
-. Within a myShop custom layout closing statements with a semicolon is mandatory, the only exceptions to this are the last line of a javascript block and the last statement with a block between braces{}
. – see third example
Below some links (in Dutch) which give more information on javascript:
- http://webtools.startpagina.nl
- http://javascript.startpagina.nl
- http://www.voorbeginner.info/javascript
- http://javascript.startkabel.nl
- http://www.w3schools.com/js/default.asp
- http://javascript.2link.be
Example 1
<head>
<!- Including a javascript file is allowed here ->
<script language="javascript" src=" http://www.mijnwinkel.nl/script/somescript.js"/></script>
</head>
<body>
<!- Including a javascript file within the body is not allowed ->
<script language="javascript" src=" http://www.mijnwinkel.nl/script/not_oke.js"/></script>
</body>
Example 2
<head>
<script type="text/javascript">
/* This form of comment is permitted. */
alert("hello"); // this form of comment is not permitted.
alert("doesnt work");
</script>
</head>
<body>
</body>
Example 3
<head>
<script language="javascript">
/* Behind each line (statement) should be a semicolon. */
alert("hello");
var i=0,n=1;
for (;i<100;i++) test(i);
function test(n){
/* Hier hoeft geen puntkomma achter, laatste statement voor een } */
alert(n)
}
</script>
</head>
<body>
</body>
Post your comment on this topic.