Javascript Basics
Javascript is a client-side scripting language which can be used to manipulate client’s browsers as well as to fetch information on a client’s machine. However, Javascript has only been used in it’s intended way recently, this is because since it’s launch back in the ’90s it has been used by spammers, hackers and virus makers to compromise client machines. The most common use of Javascript at this moment in time is for popup adverts - something which more browsers are beginning to put blocks on.
The most up to date use of Javascript has been in the creating of AJAX. AJAX is a mixture of other languages as well as Javascript which allows data to be posted back to a server without the need for pages to be reloaded. To learn more about AJAX, click here.
However good Javascript may seem to be, it has its limitations, the main one being that older browsers don’t support it.
Creating Your First Javascript
Javascript functions are located within the ‘function()’ tag. These functions can be delcared in two ways: by creating a function with its own names and variables that can be called again at any time within a script, this would be delcared in the following format: ‘function function_name(var1, var2, var3)’; functions can also be called directly which means that they can’t be used again within a script unless the code is copied since the function isn’t assigned a name, a function of this type would be declared in the following format: ‘var variable = function()’.
Any code for a function, or any part of the scipt is located within the opening and closing tags, for javascript these being ‘{’ as the opening tag and ‘}’ as the closing tag.
Variables for a function are located in the brackets after a function name - these variables are set directly each time the function is called, and can be different each time. Variables can also be set directly within a function, but these variables can’t be different each time; these variables are set using the ‘var’ tag.
Basic Page and Browser Manipulation
The main use of javascript is to manipulate client machines and web browsers - it can also be used to manipulate web pages. Browsers can be manipulated in ways that include resizing browser windows, opening new windows with custom settings as well as creating transition effects inbetween web pages.
Opening new windows with javascript is simple as there is the built in ‘window.open’ function; the variables of this function take the following form: ‘window.open(url, windowname[, variables]). Javascript can also be used to close windows by using the ‘window.close’; to use this function you can either close another window, or you can close the window which currently open. To close another window you will need to use the function in this format: ‘windowname.close();’, to close the window which is currently open you need to the function in this format: ’self.close();’.
Page transitions can be achieved with the use of special meta-tags within the ‘head’ section of a page. However, page transitions only work with Internet Explorer. To use page transitions youn will need to add a meta-tag named ‘Page-Enter’ if you want to use effects when someone enters the page, and a tag named ‘Page-Exit’ if you want effects to be used when someone leaves a page. The ‘Content’ part of the meta-tags needs to contain the information that will trigger the effects; to trigger them they will need to be wrapped in the ‘RevealTrans’ tag in the following format: ‘RevealTrans (Duration=Duration, Transition=TransitionNumber)’. The duration can be set in the tag, as well as the transition used; the transitions don’t go by name but by number; click here for a list of transitions and the numbers related to them.
Javascript can also be used to change a browser’s location. To do this the following code must be placed within a function which must be called within the ‘onLoad’ tag of the body tag of a web page: ‘window.location.href = ‘location’;’.