Script languages are tied to browser's object model, to learn them as programming language is meaningless, main part of the script associates with properties of browser's objects and calling its methods.
What is object model?
In the past, when browsers had version number equal to 1, nothing a like existed even in mind. Information was just output to the display as it came. Everything was simple, and even nuts of compatibility’ve not yet herd.
Now path of the web page to the display is much longer. Let's fallow this path.
- Page is copied from website located on a disk in the web-server to a computer memory.
- Analysis of the page is performed, and it disassembled on constituents.
- Blocks, the page composed of (like: <body></body>, <head></head>, <p></p> etc.), are placed in temporary database according to a structure of an object model.
- Data becomes available to other programs, in particular render program which output the page to a screen. For access and control of this data the web browser submits us mechanism of objects and script languages as means of access.
Contents of the data can be changed before transmitting to a browser, what is happened with dynamic web pages. But the object model continues to work during rendering the page by browser, even after page is shown on the screen. It gives us a possibility in small limits (and in last versions HTML 4.0 practically completely) to change contents of the page after loading.
Structure of an object model
To clear, what we speak about, let’s consider general scheme of the object model. Below the object model of Internet Explorer versions 4 and above is presented.
- window - object for access to the browser's window
- frames - object for access to the frames
- document - object containing the page
- all - full collection of all document tags
- forms - collection of forms
- anchors - collection of anchors
- applets - collection of applets
- embeds - collection of the embedded objects
- filters - collection of filters
- images - collection of images
- links - collection of the references
- plugins - collection of connected modules
- scripts - collection of blocks <script></script>
- selection - collection of selections
- stylesheets - collection of objects with specific styles
- history - object allowing access to visited pages
- navigator - object giving access to browser's parameters
- location - object containing current URL
- event - object giving access to events
- screen - object giving access to a screen's parameters
As you can see, the structure of the object model is rather complicated, but strictly defined. And there is a defined syntax to access to any property or method, similar to the syntax used in object oriented languages. I.e. embedded objects are separated by dot from containing, and to get access to a concrete property or method it is necessary simply correctly to construct a line of access.
Where and how to place a script code?
- The functions, which are called from a code in reply to any event
- Code of events, which call functions
// function code goes here
As you see script code is put in comment tags. Older browsers ignore it, and new programs understand it.
Well, we’ve sorted out bases of scripts, examples of popular and useful effects will be realized in the coming articles.
<< Previous Article |
Next Article >>