- Add the following new browsers to the Firefox User Agent Switcher:
Description: Nokia 6610
User agent: Nokia6610
App name: Nokia
App version: 6610
Description: BlackBerry 8100
User agent: Mozilla/4.0 BlackBerry8100
App name: BlackBerry
App version: 8100
Description: Nokia N95
User agent: NokiaN95
App name: Nokia
App version: N95
Of these: the Nokia N95 is a modern "smartphone" with a full XHTML browser;
the BlackBerry 8100 is a BlackBerry model which supports JavaScript and JPEGs
but not AJAX,
and the Nokia 6610 is a more basic phone which does not support JPEG images or
JavaScript.
- Use WURFL to develop a PHP script which writes out the page below. Only
actually show the pictures if the browser supports them. They are JPEG format
so you need to query the 'jpg' capability.
<html>
<head>
<title>Snow pictures Sat 7 Feb 2009</title>
</head>
<body>
<h1>Snow pictures Sat 7 Feb 2009</h1>
<p>It does snow in southern England, apparently! Slightly less
often than it does
in Florida, but hey, you can't have everything..... Snow fell through most
of southern England on the 2nd, and remained most of the following week.
These pictures were taken in Surrey, just west of Guildford, on the afternoon
of the 7th.</p>
<p><img src="http://edward/~nick/images/snowpic1.jpg"
alt="Snow picture 7/2/09" />
</p>
<p>Another one later the same day....</p>
<p><img src="http://edward/~nick/images/snowpic5.jpg"
alt="Snow picture 7/2/09" />
</p>
<p>
<h2>Post a comment</h2>
<form method="post" action="comment.php" />
Name: <input name='name' id='name' />
Comment: <input name='comment' id='comment' />
<input type='submit' value='Go!' />
</form>
</body>
</html>
- Test this with the Nokia N95 and the Nokia 6610 user agents. The Nokia 6610
will not support JPEG images.
- Another common use of WURFL is to generate content adapted to different
screen resolutions. For example, we can use WURFL to dynamically generate a
CSS stylesheet
with different dimensions for different page elements, depending on
the screen resolution of the device. Using this style here:
#div1
{
border-style: solid;
border-width: 2px;
border-color: red;
width: (the resolution_width capability from WURFL);
height: (the resolution_height capability from WURFL);
overflow: auto;
}
add an internal CSS stylesheet to your script, containing
the dimensions of the div with the
id of div1 using WURFL,
using the screen resolution of the device. The capabilities for screen
resolution are resolution_width for the width and
resolution_height for the height.
As an alternative you can dynamically generate an external
stylesheet from PHP; note that you will need to set
the content type of the script to text/css, i.e. begin the script with
header("Content-type: text/css");
Add some text to the
div, and test it across a
range of different user agents (the Nokia N95 and 6610, and the default user
agent i.e. the desktop browser) using the User Agent Switcher. If you
created an external stylesheet, you can link to it using:
<link rel="stylesheet" type="text/css" href="generatestyle.php" />
substituting generatestyle.php with whatever you called it.
- Try adding one of the snow photos (above) to the div and "shrinking"
it if necessary to ensure that it appears on the screen. Use the WURFL to
dynamically set the width and height attributes of the <img> tag.
The dimensions of the images are 360x270; they should be shrunk to:
width: 360 or the WURFL resolution_width, whichever is the lowest;
height: 0.75 * the width as calculated above.
This will preserve the aspect ratio of the image and ensure that the image
is contained within the screen.
- Modify your AJAX artist search page from Week 4 so that the AJAX form
and JavaScript is only included if the phone supports it. If AJAX is not
supported, use a standard HTML form with a submit button instead (you do not
have to write the search results page to respond to this form). The
capability is ajax_xhr_type and it returns 'none' if AJAX
is not supported.