AJAX - The Complete Reference

(avery) #1

428 Part II: Developing an Ajax Library^


might be acting a bit restrictive as you could lock out some users and bots, but then again
developers have to make decisions like this for better or worse. We might aim to support a
browser with full JavaScript or slightly reduced JavaScript but not one with it disabled. We
can rewrite our rating example to take this kind of approach. In this case it is best to use the
script to generate everything in the rating widget and then simply provide an error message
otherwise. We see the markup here to include the widget is quite simple.

<div id="ratingWidget1">
<noscript>
<div>Error: This feature requires JavaScript
to be enabled for correct operation.
</div>
</noscript>
</div>
<script type="text/javascript" src="ratingsdegrade.js"></script>

The included script code will populate it in the case script is on; with it off, the error
message will be shown.

Now the approach taken in this case is a bit different. As before, the widget’s init()
method is called, but this time the defaults are specified in the code as there is no markup to
read them from.

/* enable the rating widget */
AjaxTCR.util.event.addWindowLoadEvent(
var options = {
id: "ratingWidget1",
Free download pdf