|
|
|||||
|
Ready to Use Script Archive | | | Over 5000 Free Fonts | | | Tutorials | | | Javascript Forum | | | Other Javascript Resources | | | Cheat Sheet |
Further Programming - Part III
function initArray() { this.length = initArray.arguments.length for (var i = 0; i < this.length; i++) this[i+1] = initArray.arguments[i] }You don't need to understand this function. You only have to know how to use this function. If you want to create an array with three elements you just write: var MyArray= new initArray(17,18,19). 17,18,19 are assigned to the elements 1,2,3. You could as well write strings to your array. So you don't have to matter which type is used! var heyho= new initArray("This","is","cool"). Mixing different types is no problem at all: var Mixedup= new initArray(17,"yo",103). I will now initialize the array 'Mixedup' and then show the output:
This is the script for the output:
<script language="JavaScript"> <!-- Hide var Mixedup= new initArray(17,"yo",103); document.write("Element No. 1: "+Mixedup[1]+"<br>"); document.write("Element No. 2: "+Mixedup[2]+"<br>"); document.write("Element No. 3: "+Mixedup[3]+"<br>"); // --> </script>
I have written a small game yesterday. I have encountered a problem you might have got as well. If you want to clear a window or frame you look into the documentation by Netscape and see that JavaScript knows the function 'document.clear()'. But if you implement this function nothing happens! The function document.clear() seems to be broken on every platform. Gordon McComb gave me the following script which clears the window as I wanted it.
document.close(); document.open(); document.write("<P>"); You don't have to write document.write("<P>");. It is only important that you send anything to the window. This works fine with frames as well.
Now we're looking at a script which lets you navigate through different documents. What I'm talking about is the back() and forward()- function. If you have a back- link on your page this isn't the same as the back- button in the Netscape- Navigator. For example I have got some back- links which work like normal links but I know that the user probably comes from that certain page I'm linking to. The back- button provided by the Netscape Navigator goes one step back in your history list. You can do this with JavaScript as well. Just take this link in order to get back again! The script I used here is shown below:
<html> <body> <FORM NAME="buttonbar"> <INPUT TYPE="button" VALUE="Back" onClick="history.back()"> <INPUT TYPE="button" VALUE="JS- Home" onClick="location='main.htm'"> <INPUT TYPE="button" VALUE="Next" onCLick="history.forward()"> </FORM> </body> </html>You could also write history.go(-1) and history.go(1).
|
|