Java Reference
In-Depth Information
Finally, you looked at how you can check what type of browser the users have so that you can
make sure the users see only those pages or parts of a page that their browser is compatible
with. The navigator object provides you with the details you need, in particular the appName
and userAgent properties. You can also check specifi c BOM properties to see if they are sup-
ported before using them. If a browser doesn't support a specifi c property needed for your code
to work, you can either write alternative code or let users know to upgrade their browsers.
That's it for this chapter. In the next chapter, you move on to more exciting form scripting, where you
can add various controls to your page to help you gather information from the user.
Exercise Questions
Suggested solutions to these questions can be found in Appendix A. Exercise 1 Question
1.
Create a page with a number of links. Then write code that fi res on the window load event,
displaying the href of each of the links on the page. (Hint: Remember that event handlers begin
with on.)
2.
Create two pages, one called ieonly.htm and the other called notieonly.htm . Each page
should have a heading telling you what page is loaded. For example:
<H2>Welcome to the Internet Explorer only page</H2>
Using the functions for checking browser type, connect to the window object's onload event
handler and detect what browser the user has. Then, if it's the wrong page for that browser,
redirect to the other page.
3.
Insert an image in the page with the <img/> element. When the mouse pointer rolls over the
image, it should switch to a different image. When the mouse pointer rolls out (leaves the
image), it should swap back again. (Hint: These events are mouseover and mouseout .)
Search WWH ::




Custom Search