Processing of the events connected to windows, in language javascript.
We have considered how to place announcements of processing of events, such, as onmousemove in tege the document <body> for maintenance of reaction to the event which has occurred at a level of object document. Other situation - processing of event on a loss window. In internet explorer it is possible to place such instructions in teg opening <html>:
<html onmousemove = " mymousemovecode () "
onclick = " myclickcode () ">
...
</html>
There is one more reception of a designation of function processing event in line with the identifier of an element and event. In this case the name of event and a name of an element divide{share} a point. But thus it is necessary to mean, that these methods are not standard for processing events. Simply they work, because functions are set in properties of object element:
<h2 id=myheading> the Text reacting to event </h2>
...
<script language=javascript>
function myheading.onclick () {
alert (' you have clicked the Text! ');
}
</script>
This method use for processing the events connected to the basic objects of a browser - document and window:
<script language=javascript>
function window.onload () {
alert (' Loading of page is completed. ');
}
</script>
Cancellation of action of event.
Some events, such as onsubmit, allow to operate that as the browser will lead itself in reply to them, returning control value. We shall consider an example with the form containing a unique text field email, and the button submit (Sending):
<form id=myform onsubmit = " return checkaddress () "
action = " http: // www.some-web.com/file.cgi ">
<input type=text id=email>
<input type=submit>
</form>
<script language=javascript>
function checkaddress () {
straddress = document.forms ["myform"] .elements ["email"] .value;
if (straddress.indexof ()! =-1) // contains a symbol
return true
else
}
alert (' Check up correctness e-mail addresses! ');
return false
}
}
</script>
Here for search of a symbol in a line entered by the user in the form, function " indexof () " is used. If in line there is no such symbol, function will return value-1. In this case it is meant, what is it cannot be correct e-mail. About it the message is given out, and sending is cancelled by transfer of value false. We had been used a keyword return in attribute of an element onsubmit so the result comes back in that part of a browser which is engaged in sending.
In the resulted example it is visible, as it is used brouzernaja model for reception of the text from a text field. The required line is property value an element email. This form - a part of a collection elements forms myform, stored{kept} in a collection forms object document.
Instead of returning value actually function we can cancel the action by default appointed for the given event, with the help of property returnvalue object event. We shall consider it in the following releases.

|