Java Reference
In-Depth Information
C HAPTER 9: U SING J AVA S CRIPT
• JavaScript and Bots
• Processing Automatic Choice Lists
• Supporting JavaScript Includes
• Processing JavaScript Forms
Many web sites make use of JavaScript. JavaScript is a language that allows you to embed
Java-like instructions into a web site. This allows the user's web browsing experience to be
much more interactive. However, JavaScript also makes creating a bot, for a JavaScript en-
abled web site, much more complex.
When a bot encounters JavaScript, the bot will not automatically execute the JavaScript,
as a regular browser would do. Rather, you, the bot programmer, must examine the Java-
Script first and understand which HTTP requests your bot must send to emulate the browser.
This chapter will show you some techniques for how to handle JavaScript.
Understanding JavaScript
Though JavaScript is similar to Java, there are many important differences. It is a com-
mon misunderstanding that Java and JavaScript are the same thing. This is not at all the case.
The following are some of the important differences between Java and JavaScript:
• Java uses types, such as int
• JavaScript is typeless, everything is an object
• Java and JavaScript use different syntax for functions
• Java was developed by Sun Microsystems
• JavaScript was developed by NetScape, based on Java
It is important that you understand these differences, if you are to create bots that access
sites that make use of JavaScript.
JavaScript occurs between a beginning <script> and ending </script> tags.
For example, the following code fragment defines a JavaScript function.
<script type="text/javascript">
function formValidate(form){
if( form.interest.value.length==0 )
alert("You must enter an interest rate.");
else if( form.principle.value.length==0 )
alert("You must enter a principle.");
else if( form.term.value.length==0 )
 
Search WWH ::




Custom Search