Blackberry Wap-41 Development Guide
Blackberry Wap-41 Development Guide
Blackberry Wap-41 Development Guide
Handheld Browser
Version 4.1
At the time of publication, this documentation complies with BlackBerry handheld software version 4.1.
©2005 Research In Motion Limited. All Rights Reserved. The BlackBerry and RIM families of related marks, images, and symbols are the
exclusive properties of Research In Motion Limited. RIM, Research In Motion, “Always On, Always Connected”, the “envelope in motion”
symbol, BlackBerry, and BlackBerry Enterprise Server are registered with the U.S. Patent and Trademark Office and may be pending or
registered in other countries.
IBM, Lotus, Domino, and Lotus Notes are trademarks of IBM in the United States. Microsoft is a registered trademark of Microsoft Corporation
in the United States and/or other countries. Microsoft and Windows NT are either registered trademarks or trademarks of Microsoft
Corporation in the United States and/or other countries. Adobe and Photoshop are registered trademarks of Adobe Systems Incorporated in
the United States, and/or other countries. Java and all trademarks and logos that contain Java are trademarks or registered trademarks of Sun
Microsystems, Inc. in the United States and other countries. Mobitex is either a registered trademark or trademark of Telefonaktiebolaget LM
Ericsson Corporation. All other brands, product names, company names, trademarks and service marks are the properties of their respective
owners.
The software referenced in this guide facilitates the creation of content for the BlackBerry Browser. In order to use the software referenced
herein as intended, you must have valid agreements in place with the licensor(s) of the hardware and software referenced in this user guide. In
addition to being required to comply with such license terms, you are strictly prohibited from using the software referenced herein to create,
adapt, or otherwise use in any fashion any content that infringes upon or violates the intellectual property rights of any third-party. The
disclaimer of liability set forth above shall apply with respect to your use of the software in any manner not authorized by Plazmic, Inc.
The BlackBerry device and/or associated software are protected by copyright, international treaties and various patents, including one or more
of the following U.S. patents: 6,278,442; 6,271,605; 6,219,694; 6,075,470; 6,073,318; D445,428; D433,460; D416,256. Other patents are
registered or pending in various countries around the world. Visit www.rim.com/patents.shtml for a list of RIM [as hereinafter defined]
patents.
This document is provided “as is” and Research In Motion Limited and its affiliated companies (“RIM”) assume no responsibility for any
typographical, technical or other inaccuracies in this document. RIM reserves the right to periodically change information that is contained in
this document; however, RIM makes no commitment to provide any such changes, updates, enhancements or other additions to this document
to you in a timely manner or at all. RIM MAKES NO REPRESENTATIONS, WARRANTIES, CONDITIONS OR COVENANTS, EITHER EXPRESS OR
IMPLIED (INCLUDING WITHOUT LIMITATION, ANY EXPRESS OR IMPLIED WARRANTIES OR CONDITIONS OF FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, MERCHANTABILITY, DURABILITY, TITLE, OR RELATED TO THE PERFORMANCE OR NON-PERFORMANCE OF
ANY SOFTWARE REFERENCED HEREIN OR PERFORMANCE OF ANY SERVICES REFERENCED HEREIN). IN CONNECTION WITH YOUR USE OF
THIS DOCUMENTATION, NEITHER RIM NOR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES OR CONSULTANTS SHALL BE LIABLE TO
YOU FOR ANY DAMAGES WHATSOEVER BE THEY DIRECT, ECONOMIC, COMMERCIAL, SPECIAL, CONSEQUENTIAL, INCIDENTAL,
EXEMPLARY OR INDIRECT DAMAGES, EVEN IF RIM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, INCLUDING WITHOUT
LIMITATION, LOSS OF BUSINESS REVENUE OR EARNINGS, LOST DATA, DAMAGES CAUSED BY DELAYS, LOST PROFITS, OR A FAILURE TO
REALIZE EXPECTED SAVINGS.
This document might contain references to third party sources of information, hardware or software, products or services and/or third party
web sites (collectively the “Third-Party Information”). RIM does not control, and is not responsible for, any Third-Party Information, including,
without limitation the content, accuracy, copyright compliance, compatibility, performance, trustworthiness, legality, decency, links, or any
other aspect of Third-Party Information. The inclusion of Third-Party Information in this document does not imply endorsement by RIM of the
Third Party Information or the third party in any way. Installation and use of Third Party Information with RIM's products and services may
require one or more patent, trademark or copyright licenses in order to avoid infringement of the intellectual property rights of others. Any
dealings with Third Party Information, including, without limitation, compliance with applicable licenses and terms and conditions, are solely
between you and the third party. You are solely responsible for determining whether such third party licenses are required and are responsible
for acquiring any such licenses relating to Third Party Information. To the extent that such intellectual property licenses may be required, RIM
expressly recommends that you do not install or use Third Party Information until all such applicable licenses have been acquired by you or on
your behalf. Your use of Third Party Information shall be governed by and subject to you agreeing to the terms of the Third Party Information
licenses. Any Third Party Information that is provided with RIM's products and services is provided "as is". RIM makes no representation,
warranty or guarantee whatsoever in relation to the Third Party Information and RIM assumes no liability whatsoever in relation to the Third
Party Information even if RIM has been advised of the possibility of such damages or can anticipate such damages.
This product includes software developed by the Apache Software Foundation (http://www.apache.org/) and/or licensed pursuant to
Apache License, Version 2.0 (http://www.apache.org/licenses/). For more information, see the NOTICE.txt file included with the software.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and
limitations under the License.
Published in Canada
Contents
1 The BlackBerry Wireless Handheld browser...................................................................................................... 9
Using the BalckBerry Wireless Handheld browser ................................................................................................ 9
Browser configurations................................................................................................................................................... 9
WAP Browser configuration................................................................................................................................10
BlackBerry Browser configuration.....................................................................................................................11
Mobile Data ServiceInternet Browser configuration ..................................................................................12
Browser feature support...............................................................................................................................................13
Browser content support..............................................................................................................................................15
Handling multi-part content ..............................................................................................................................17
Determining which markup languages are accepted ................................................................................17
Image conversion ..................................................................................................................................................17
Index....................................................................................................................................................................... 205
1
The BlackBerry Wireless Handheld browser
Using the BalckBerry Wireless Handheld browser
Browser configurations
Browser feature support
Browser content support
This guide provides an overview of the technical aspects browser and outlines design considerations for different
browser configurations.
Browser configurations
BlackBerry devices provide up to three browser configurations:
• WAP Browser: connects to the network using a WAP gateway
• BlackBerry Browser: connects to the network using the Mobile Data Service of the BlackBerry Enterprise
Server®
• Internet Browser: connects to the network using the BlackBerry Internet Service
BlackBerry Wireless Handheld Browser Content Developer Guide
Each browser configuration represents a different setup of the same browser software. The following table
summarizes the characteristics of each configuration:
When a browser configuration is provisioned on the handheld, separate configuration-specific icons appear on the
BlackBerry Home screen. To use a specific browser configuration, a BlackBerry user selects the appropriate icon.
Users can select the configuration that is optimal for the type of content that they are viewing. For example, users
might use the WAP Browser to browse standard Wireless Markup Language (WML) content on the Internet and
use the BlackBerry Browser to access a corporate intranet and view mobile media.
Corporate system administrators can set an IT policy on the BlackBerry Enterprise Server to specify the default
browser that is used for URLs in applications other than the browser, such as in email messages or memos. Users
can also change the default browser. For more information on changing the default browser configuration, see the
on-device help.
1. Research In Motion does not in any way endorse or guarantee the security, compatibility, performance, or trustworthiness of any WAP gateway, and shall have
no liability to you or any third party for issues arising from such WAP gateway.
10
1: Browser configurations
• no vCard support
• no vCalendar support
• limited Wireless Telephony Application Interface (WTAI) support: the browser only supports the Uniform
Resource Identifier (URI) forms of the public WTAI functions
• Limited WAP Cascading Style Sheet (CSS) support
The WAP Browser is designed to use WTLS to access secure WAP services, including WTLS Class 1 (encryption
only, no authentication) and WTLS Class 2 (encryption and server authentication). The WAP Browser configuration
supports the following protocols:
• WAP 1.2.1: The WAP Browser caches WSP headers to decrease the transmission time of requests; it sends
common HTTP headers to the WAP gateway when the WAP connection is first set up, and then sends only
additional or changed headers in each request. In subsequent requests, the WAP Browser sends only headers
that are specific to the request or that contain values that are different from the values that were set up at the
start of the connection.
See the specification WAP-203-WSP-20000504-a at http://www.wapforum.org for more information.
• WAP 2.0: Sends HTTP over Wireless-Profiled TCP (wTCP). The HTTP request is sent to a WAP 2.0 proxy, which
then forwards it on to the server.
The WAP gateway determines which content types are supported. For example, some WAP gateways might
convert HTML content into a series of WML pages, while some might impose a limit on the size of content that the
WAP Browser can request, and so on.
11
BlackBerry Wireless Handheld Browser Content Developer Guide
12
1: Browser feature support
13
BlackBerry Wireless Handheld Browser Content Developer Guide
14
1: Browser content support
15
BlackBerry Wireless Handheld Browser Content Developer Guide
16
1: Browser content support
Image conversion
Note: The image conversion feature requires the BlackBerry Enterprise Server for Microsoft® Exchange version 3.6 or later or the
BlackBerry Enterprise Server for IBM® Lotus® Domino® version 2.2 or later.
The browser includes the following HTTP headers with every request to provide the information that the gateway
needs to convert images so that they can be rendered by the browser:
• Transcode Content (X-RIM-transcode-content) enables image optimization processing by indicating which
image types should be converted.
• User Agent Profile (Profile) contains a URL that includes the following information:
• location of the User Agent Profile (UAPROF) documents on the Internet
• device model number
17
BlackBerry Wireless Handheld Browser Content Developer Guide
Image processing
The browser loads images differently depending on the gateway that is used.
When processing images for display on the handheld, the following techniques apply:
• Horizontal scaling: Images that exceed the screen dimensions are scaled to be no wider than the screen
content area. To maintain the aspect ratio, images are scaled by the same factor in both the horizontal and
vertical dimensions. The screen content area is the screen width minus 5 pixels. The vertical scroll bar that
displays at the right is 5 pixels wide.
• Vertical scaling: Images that are more than twice the screen height are scaled to twice the screen height. To
maintain the aspect ratio, images are scaled by the same factor in the horizontal and vertical dimensions.
Users roll the trackwheel to scroll vertically.
• Size limitation: If a monochrome image is more than 8192 bytes after scaling, the image is discarded. If the
image is part of a link, the browser displays the alternate text for the image.
18
1: Browser content support
• Color: On a monochrome handheld, color images are dithered into a monochrome image. On a color
handheld, the image color depth is reduced to accommodate the number of colors that the device supports.
• Vertical alignment: The vertical alignment in <img> tags is ignored.
The Mobile Data Service and Internet Browsing Service automatically scale and dither images for the BlackBerry
device. With the WAP Browser configuration, the device performs scaling and dithering as necessary.
Note: In the BlackBerry Wireless Handheld software version 3.6 or earlier, the browser displays images in a vertical area that is separate
from the content before and after the image. Images do not appear inline with surrounding text; they are aligned horizontally according
to the ALIGN attribute (ALIGN=LEFT or ALIGN=RIGHT).
19
BlackBerry Wireless Handheld Browser Content Developer Guide
20
2
Browser interface and features
Browser screen
Browser features
Browser screen
By default, the handheld browser is designed to display a non-scrolling title bar at the top of each page that
displays the following items:
• page title
• unread messages
• pending service books
• connection information
• security settings
• network signal strength
When the browser requests or loads pages, a progress bar appears at the bottom of the screen.
On WML pages, <do> elements appear both as soft keys in the non-scrolling section at the bottom of the page
and as menu items on the browser menu. See "Browser menus" on page 21 for more information.
Links to web pages, phone numbers, and email addresses are underlined with a dotted line. See "Links" on page
22 for more information.
When a web page does not fit on one screen, a vertical scroll bar appears on the right side of the screen.
Browser menus
The browser menu provides access to most tasks that users perform when they browse. The menu provides the
standard BlackBerry system menu items, such as Hide Menu and Close, a Help item, and appropriate context
menu items such as Select and Find.
The browser provides standard menu items for navigation, including Home, Back, Forward, History, and Refresh.
The Go To menu item enables users to type any URL.
Specific menu items appear depending on the page and the item that is selected.
BlackBerry Wireless Handheld Browser Content Developer Guide
Links
Links are underlined with a dotted line. In BlackBerry handheld software version 3.7 or later, the browser provides
one-click navigation. To follow a selected link, users click and hold the trackwheel or press the Enter key.
22
2: Browser features
Option lists
Option lists are displayed as radio buttons (for single-selection lists) or check boxes (for multiple-selection lists). To
select an option in a list, users press the Space key or click the Select Option menu item.
In WML, if a single-selection list does not have an onpick action defined for one of its options, when the user
selects an option, the browser runs either the first <do> action with a type of accept, or, if none have the type
accept, the first <do> action listed.
In HTML and XHTML, options that are grouped in a SELECT tag appear in a drop-down list. To select an option,
users click the drop-down menu and click Change Option.
If a size is defined, the selection list appears in a vertical list instead of a drop-down list.
Browser features
History
The browser maintains a navigation history of up to 20 items. When a user navigates to a page, the URL of that
page is added to the navigation history.
When the history list reaches 20 items, new URLs replace the earliest pages. If memory on the handheld becomes
low, the browser removes history items to free memory.
When the user navigates to a previous page and selects a new link from that page, the browser removes any URLs
after that point in the history. The URL of the newly selected page becomes the next item in the history sequence.
For example, if a user navigates from a music page to a news page, the history displays both pages. If the user
then navigates back to the music page and selects a genre of music, the history displays the music page and the
genre page; the news page is no longer listed.
If a user visits a WML page by some manner other than a predefined link (for example, not a bookmark or the Go To dialog box), or if
that page has a newcontext attribute defined, the browser automatically clears the history before displaying the new URL. This
behaviour is required to conform to WML security specifications.
Cookies
If enabled, the Mobile Data Service or BlackBerry Internet Service store cookies on behalf of the handheld. These
services support cookies based on the RFC 2965 HTTP State Management Mechanism, which supports the HTTP
state management header Set-Cookie-2. See the BlackBerry Enterprise Server Administration Guide for more
information.
Unless these services are configured to do so, the browser stores cookies on its own behalf. The browser supports
standard cookies based on the RFC 2109 HTTP State Management Mechanism, as well as the Netscape® format
for expiry dates (EXPIRES=Weekday, DD-Month-YY HH:MM:SS GMT). The browser maintains cookies when the
device is turned off.
23
BlackBerry Wireless Handheld Browser Content Developer Guide
Cache
The browser stores content in several different caches, depending on the type of data it is. Whenever possible, the
browser loads requested content from the local cache.
Users can clear the content, channel, and cookie caches on the device to free remaining memory and refresh any
visited web pages.
Cache Description
Content This cache includes the raw data cache; it contains all data that is cached as a result of normal browser activity.
Channel This cache contains data that is sent to the handheld by a channel or cache push.
Cookie This cache contains cookies that are assigned to the browser by visited web pages.
The browser respects cache control directives that web servers send in responses, such as Expires, Max-Age, and
Cache-Control. When permitted, the browser retrieves content from the cache based on associated cache control
directives. See the specification WAP-120-UACACH-20010413-a at http://www.wapforum.org for more
information on WAP user agent caching.
On BlackBerry devices, the channel and cookie caches are saved in persistent storage, so information is saved even
if the device is reset. An item is removed from the cache when it expires. If an expiry time is not set explicitly for an
item, the item is removed from the cache after 29 days.
On devices with 8 MB of memory, the content cache is cleared when the user closes the browser. On devices with
16 MB of memory, the content cache persists. The device removes items from the cache to free memory when
necessary, with expired pages removed first.
Service providers can set the size of the raw data cache. The system defaults for the various BlackBerry devices are:
• 200 KB for handhelds with 8MB of memory
• 500 KB for handhelds with 16MB of memory
• 2 MB for handhelds with more than 16MB of memory
Users cannot view or change these options.
Note: The channel and cookie caches are stored persistently; however, information in the content cache is lost if the
handheld is reset or the Mobile Data Service is restarted.
To enable conditional GET requests, content developers must use the following HTTP headers.
Bookmarks
The BlackBerry device browser provides bookmark support that combines the functionality that is typical of
computer-based browsers with added features that are designed specifically for the wireless environment.
As with desktop browsers, users can add bookmarks for any web site that they visit, and they can create a
hierarchy of folders to organize them. Each browser configuration has its own set of bookmark folders, so that
users can organize bookmarks separately based on which browser configuration is best for the bookmarked site.
Bookmark folders for all browser configurations can be accessed regardless of the browser configuration that the
user is browsing with. Users can move or copy bookmarks between any folder. They can edit the title and URL of
bookmarks as necessary, and they can search for and delete specified bookmarks.
24
2: Browser features
During the registration process, service providers can insert a set of customized bookmarks in the browser. These
bookmarks are sent over the wireless network in the browser configuration service record. By default, the
bookmarks are placed in the Bookmarks tree view hierarchy in a new folder called Carrier Bookmarks. The name of
the folder can also be customized.
Frequently used browser pages can also be saved to the Messages screen for quick access.
Bookmarks are useful when users are outside a wireless network coverage area. When users add a bookmark, they
can make the bookmark available offline, which means that both the content and URL of the page are saved.
Offline bookmarks are maintained even if the device is reset.
Offline bookmarks for web pages that contain forms also save the current values of form fields, which users can
use as a template for frequently used forms. For example, users can add an offline bookmark for a page that
contains a form. Later, even if users are outside a wireless network coverage area, they can load the bookmarked
form, fill out the appropriate fields, and submit the form. Users can then save the browser request to the messages
list. When the device returns to a wireless coverage area, the browser sends the request automatically.
Users can back up browser bookmarks using the BlackBerry Desktop Software so that when they update their
devices with new software, their bookmarks are retained.
25
BlackBerry Wireless Handheld Browser Content Developer Guide
26
3
Designing wireless web content
Creating effective content
Creating effective images
Defining queues for offline form submission
Delivering device-specific content
• Add links to related content: If you divide related content into more than one page, make links to related
content easily accessible. Make sure that links to related content are visible in a non-scrolling area of the page
or at the top of the page. For example, you could add a More menu item (or soft key) to enable users to
retrieve related content quickly.
28
3: Creating effective images
29
BlackBerry Wireless Handheld Browser Content Developer Guide
monochrome handheld. See "Defining queues for offline form submission" on page 31 for more information
on delivering device-appropriate content.
30
3: Defining queues for offline form submission
31
BlackBerry Wireless Handheld Browser Content Developer Guide
You can creating form queues using these headers either by creating an HTTP property file or by adding the
queuing parameters directly to the HTML or WML page.
You can add queuing parameters for additional forms within the same header file.
For a complete sample of the property file, see “Offline form queue header file: .htaccess” on page 32.
32
3: Making requests for content conditional
Header Description
If-Modified_Since This header is used with a GET method to request that the web server transfer content only if it has been
modified since the specified date and time. For example:
If-Modified-Since: Fri, 6 May 2005 12:00:00 GMT
The request is handled as follows:
• If the requested content has been modified since the specified date, or if the specified date is invalid (such
as a date that is later than the server’s current time), the content will be downloaded as normal.
• If the requested content has not been modified, the server sends a 304 (not Modified) response, and the
browser retrieves the content from the cache.
33
BlackBerry Wireless Handheld Browser Content Developer Guide
Header Description
Last-Modified This header identifies the date and time at which the web content was most recently modified. For example:
Last-Modified: Fri, 6 May 2005 12:00:00 GMT
Note: The exact meaning of this header field depends on the implementation of the origin server and the nature
of the original resource:
• For files, it may be just the file system last-modified time.
• For entities with dynamically included parts, it may be the last-modified time of the most recently modified
component.
• For database gateways, it may be the last-update time stamp of the record.
Other headers are also included which help determine what content is sent. For example, the Accept header
specifies the content types that the browser accepts. The preferred content type is determined by the order of
content types in the Accept header, from left to right. For example, the following header indicates that WML is
preferred over HTML, and .gif images are preferred over .png images:
Accept: text/vnd.wap.wml, text/html, image/gif, image/png
34
3: Delivering device-specific content
3. Write a browser detection script that parses the Profile header to determine the browser type and the
supported content types, and returns content that is appropriate for the requesting browser. See "Write a
browser detection script" on page 35 for more information.
4. Deploy the browser detection script on your web application server.
5. Test the script by requesting content from a variety of browsers.
35
BlackBerry Wireless Handheld Browser Content Developer Guide
# Note: URLs are used in this example for non-existent web sites.
#!c:\perl\bin\
$content = $ENV{'HTTP_ACCEPT'};
$browser = $ENV{'HTTP_USER_AGENT'};
if ($content =~ html) {
if ($browser =~ BlackBerry) {
print "Location: http://mobile.blackberry.com/index.html", "\n\n";
}
elsif ($browser =~ Mozilla) {
print "Location: http://www.blackberry.com/index.shtml", "\n\n";
}
}
elsif ($content =~ wml) {
if ($browser =~ BlackBerry) {
print "Location: http://mobile.blackberry.com/wml/index.wml", "\n\n";
}
else {
print "Location: http://www.blackberry.com/unsupported.html", "\n\n";
}
}
else {
print "Location: http://www.blackberry.com/index.shtml", "\n\n";
}
36
3: Delivering device-specific content
7. To accommodate monochrome handhelds by default, specify the BlackBerry 6210 Wireless HandHeld™ as the
default model. By default, the server includes monochrome images in the HTTP response.
model="6210"
8. Include an If statement to verify that a BlackBerry device sent the Profile header.
If ( InStr( uaprof, "http://www.blackberry.com/go/mobile/profiles/uaprof/" ) = 1 )
9. Assign the 4-character string starting at position 53 to the model variable.
Then
model = Mid( uaprof, 53, 4 )
End If
10. Include an If statement to return a color image if the handheld supports color, and a monochrome image if it
supports black and white images only.
if ( model >= 7000 ) Then
Response.write( "<img src=""images/BBLogoClr.gif"" alt=""BlackBerry""/><br/><br/
>" )
Else
Response.write( "<img src=""images/BBlogo.wbmp"" alt=""BlackBerry"" /> " )
End If
%>
<p align="center">
<%
' Detect colour devices (model number 7XXX)
uaprof = request.servervariables("HTTP_PROFILE")
37
BlackBerry Wireless Handheld Browser Content Developer Guide
End If
%>
38
4
Creating XHTML pages
Using XHTML-MP
Creating an XHTML-MP page
Using XHTML-MP
XHTML-MP is a subset of XHTML 1.1, extended with some WAP-specific tags. It has been designed for use by
handhelds with smaller displays and limited memory and CPU power. XHTML 1.1 is a superset of HTML 4.0. See
WAP-277-XHTMLMP-20011029-a at http://www.openmobilealliance.org/tech/affiliates/wap for more
information.
The browser ignores any tags that are not part of the XHTML-MP subset and displays content as if the enclosing
tags are not present. See "XHTML Mobile Profile reference" on page 89 for more information.
• Text placed at angles and other text extension elements are not supported. To create text object effects,
consider using SVG for your mobile media content.
• Scripts and events: The BlackBerry device browser supports JavaScript, but does not support applets. The
browser reads the contents of a <script> tag, including any event-handler attributes. Only a limited subset
of event handlers are supported. See "JavaScript language reference" on page 129 for more information.
• Forms: XHTML-MP supports basic forms. The standard keyboard on BlackBerry devices enables users to easily
type text into forms. File and image input types are not supported. Developers who want to create forms for
writing content to the device file system should consider writing a Java application.
The BlackBerry device browser allows you to set up queues so that users can fill out and submit forms even
when they are outside of a wireless coverage area. See "Creating an XHTML-MP page" on page 40 for more
information.
• Tables: The browser supports tables. Users can enable HTML table support to properly display tables that fit
within the screen width of the handheld. Larger tables are split apart with the table cells displayed in vertical
sequence. Tables cannot be nested within each other.
You should test tables thoroughly in the BlackBerry Browser to verify that they display appropriately on the
device.
• Frames: The browser does not support frames (<frameset> or <iframe>) because the complex page layouts
that frames provide are typically not appropriate for the size of BlackBerry device screens.
If a web page contains a frameset, the browser displays a list of the frames in the frameset so that users can
open a selected frame as a standalone page.
40
4: Creating an XHTML-MP page
41
BlackBerry Wireless Handheld Browser Content Developer Guide
42
4: Creating an XHTML-MP page
</td>
<td width="55%">
<input type="text" name="symbol" size="6"/>
</td>
</tr>
5. Add a row containing a drop-down list that enables users to select the exchange on which the stock is listed.
Omit the size attribute of the <select> element to display the radio buttons as a drop-down list instead of
a list box.
<tr>
<td >
Listed on:
</td>
<td>
<select name="exchange">
<option>TSE</option>
<option>NYSE</option>
<option>NASDAQ</option>
<option>Dow Jones</option>
</select>
</td>
</tr>
6. Add a row that contains a group of radio buttons that allow users to choose whether they are notified when
the stock price changes by a specified amount or when the stock price hits a high or low target price.
<tr>
<td>
Notification trigger:
</td>
<td>
<input type="radio" name="notify" value="change" checked>
Target price change
</input><br/>
<input type="radio" name="notify" value="high-low">
Target high/low values
</input>
</td>
</tr>
7. Add a row containing a series of check boxes that enable users to select items that are included in the
notification, such as a chart or news items related to the selected stock.
<tr>
<td>
Include with push:
</td>
<td>
<input type="checkbox" name="chart">Performance chart</input><br/>
<input type="checkbox" name="articles">Related articles</input>
</td>
</tr>
8. Create a submit button and add a reset button to enable users to reset all values to the defaults.
<input type="submit" name="submit" value="Register">
<input type="reset" value=" Reset ">
43
BlackBerry Wireless Handheld Browser Content Developer Guide
9. Add three hidden inputs for user-supplied values. These values are set through a series of JavaScript dialog
boxes.
<input type="hidden" name="change" value="" />
<input type="hidden" name="maxtarget" value="" />
<input type="hidden" name="mintarget" value="" />
Add graphics
Tip: When you create pages to be viewed on wireless devices, avoid using unnecessary images. A recognizable logo is one image you
should include, so that visitors will know that they have arrived at the correct page.
</div>
<hr/>
2. Add an email link to your page.
<a href="mailto:[email protected]">Email</a>
3. Add a phone link to your page.
<a href="tel:416-555-0000">Telephone</a>
Add styles
1. Create styles using WAP CSS syntax. These styles can be nested under a <style> element that is located
between the <head> and </head> elements or included in a separate CSS file.
div.navigation {
background-color: lightgrey;
font-family: arial;
font-size: 4pt;
}
44
4: Creating an XHTML-MP page
2. If you have created an external style sheet, between the <head> and </head> elements, add a <link>
element. This element must have attributes that define the name of the CSS file and identify the content as
style properties.
<link rel="stylesheet" href="stock-monitor.css" type="text/css" />
The complete CSS file is provided at the end of this section. See "stock-monitor.css" on page 50 for more
information.
1. Between the <head> and </head> elements, add a <script> element and define the script language as
JavaScript.
<script type = "text/javascript">
</script>
2. Between the <script> and </script> elements, define a function called ValidateForm().
function ValidateForm() {
3. Add a routine to verify that the user has specified an email address. If no email address has been specified,
display a dialog box.
if ((emailID.value==null)||(emailID.value=="")) {
alert("Please Enter your Email Address");
emailID.focus();
return false;
}
4. Add a routine to verify that the user has specified a stock symbol. If no stock symbol has been specified,
display a dialog box.
if ((symbol.value==null) || (symbol.value=="")) {
alert("Please enter a symbol for the financial product you want
to monitor.");
symbol.focus();
return false;
}
5. Add a routine to determine if the user selected the Target change value notification trigger. If so, display a
dialog box that enables the user to specify the amount by which the stock price must change to trigger a
notification.
if(document.monitor.notify[0].checked) {
change = prompt("Specify the value change for " + symbol.value +
" required to trigger a notification: ", change);
if (confirm("You will be notified when " + symbol.value + " changes by
at least $" + change + " per share, based on it's value
at the time ofregistration")==true) {
document.monitor.change.value = change;
return true;
} else {
return false;
}
45
BlackBerry Wireless Handheld Browser Content Developer Guide
}
6. Add a routine to determine if the user selected the Target high/low value notification trigger. If the user
has selected the check box, display a dialog box that enables the user to specify a target high followed by a
dialog box that enables the user to specify a target low.
if(document.monitor.notify[1].checked) {
maxtarget = prompt("Please enter the target high value for " +
symbol.value + ":", maxtarget);
mintarget = prompt("High value set at $" + maxtarget + ". Please
enter the target low value:", mintarget);
if (confirm("You will be notified when the financial product " +
symbol.value + " reaches a high of $" + maxtarget + " or
a low of $" + mintarget + " per share.")==true) {
document.monitor.maxtarget.value = maxtarget;
document.monitor.mintarget.value = mintarget;
return true;
} else {
return false;
}
}
7. Add an onSubmit event handler to the <form> element, which calls the ValidateForm() JavaScript function
created in step 1.
<form name="monitor" method="post" action="bb-broker.php" onSubmit="return
ValidateForm()">
> Between the <form> and </form> elements, add a hidden <input> element for each header that you want
to define. The x-rim-request-title property must be defined; other queuing parameters are optional.
For each <input> element, the name attribute corresponds to the header name (for example,
x-rim-queue-id), while the value attribute defines the value for that header.
<input type="hidden" name="x-rim-queue-id" value="Register" />
<input type="hidden" name="x-rim-request-title" value="Stock Monitor
Registration" />
<input type="hidden" name="x-rim-next-target" value="success.html" />
See "Defining queues for offline form submission" on page 27 for more information about the headers that
are used to define form queues.
Tip: You can also set up forms by formatting your web site with the necessary headers. See "Defining queues for
offline form submission" on page 27 for more information.
46
4: Creating an XHTML-MP page
Test content using a BlackBerry device or by using the BlackBerry device simulator. The BlackBerry device
simulator is included with the BlackBerry Java Development Environment (JDE) and the Plazmic Content
Developer Kit (CDK). The simulator’s browser application includes a built-in WAP gateway, so that you can test
WML pages by opening them in the browser. See "Testing web pages" on page 65 for more information.
Example: stock-monitor.xhtml
<!-- Adding a meta tag define how this page may be cached. -->
<meta http-equiv="cache-control" content="public" />
<!-- Creating a javascript which checks input and selections, and requests
further information through dialogs. -->
<script type = "text/javascript">
function ValidateForm() {
47
BlackBerry Wireless Handheld Browser Content Developer Guide
}
</script>
</head>
<body>
48
4: Creating an XHTML-MP page
</td>
<td width="55%">
<input type="text" name="symbol" size="6"/>
</td>
</tr>
<tr>
<td >
Listed on:
</td>
<td>
49
BlackBerry Wireless Handheld Browser Content Developer Guide
<!-- Adding some hidden inputs that will be set via the ValidateForm()
javascript function. -->
<input type="hidden" name="change" value="" />
<input type="hidden" name="maxtarget" value="" />
<input type="hidden" name="mintarget" value="" />
<!-- Adding some hidden inputs that define the queue for the offline
submission of the form. -->
<input type="hidden" name="x-rim-queue-id" value="Register" />
<input type="hidden" name="x-rim-request-title" value="Stock Monitor
Registration" />
<input type="hidden" name="x-rim-next-target" value="success.html" />
</form>
</body>
</html>
Example: stock-monitor.css
p {
font-family: arial;
font-size: 6pt;
colour: black
}
table {
background-color: lightgrey;
font-family: arial;
font-size: 6pt;
}
input {
-wap-input-required: true;
font-family: arial;
font-size: 6pt;
}
select {
font-family: arial;
font-size: 6pt;
border-width= 0pt;
}
div.navigation {
background-color: lightgrey;
50
4: Creating an XHTML-MP page
font-family: arial;
font-size: 4pt;
}
a {
color: darkblue
}
51
BlackBerry Wireless Handheld Browser Content Developer Guide
52
5
Creating WML pages
Using WML
Creating a WML page
Using WML
WML is an XML language that conforms to XML 1.0 rules; for example, tags are case-sensitive, and every opening
tag must either have a corresponding closing tag or be self closing. The browser supports WML 1.3 and WML
Script 1.2.1. See "Wireless Markup Language (WML) reference" on page 119 for more information on supported
WML tags.
Note: The browser supports WML Script except for the Float standard library and all functions that use floating point values. Floating
point refers to numbers with varying number of digits before or after the decimal point; that is, the decimal point can float.
WML is primarily a text-based language that facilitates chunking information into small sections for display on
mobile devices. Because of the small screen size, typical desk-top-oriented HTML pages do not typically display
effectively on a mobile browser. HTML content is generally designed for a much larger space, and it often includes
elements such as complex tables or framesets that render poorly or not at all on the handheld browser. Also, the
amount of text on most HTML sites results in a browsing experience that requires a great deal of scrolling.
WML breaks down information into chunks, called “cards.” Each card contains a single topic, or about a screen’s
worth of content. These related WML cards are then connected using navigational links. A set of related WML
cards are included in a single .wml file, which is referred to as a “deck.” From an HTML perspective, it is similar to
creating a single HTML file that includes multiple <body> sections.
WML offers several advantages for mobile browsers:
• WML decks reduce the number of client-server transactions; decks are transmitted as individual pages.
• WML cards provide an optimal device browsing experience because chunks of content display as a single
screen and they require minimal scrolling.
• WML has a small tagset compared to HTML.
• WML supports forms, option lists, and text entry, which is ideal for users who want to retrieve specific
information.
54
5: Creating a WML page
Add a template
WML templates enable you to include content in several cards at the same time. Using templates saves time and
minimizes the content that is sent over the wireless network; content that is duplicated across multiple cards only
needs to be included once in the deck. Templates can only contain <do> and <onevent> tags.
55
BlackBerry Wireless Handheld Browser Content Developer Guide
In this example, we want to add a help menu item that is available for each card.
1. Create the template by inserting the following tag immediately following the <wml> tag:
<template>
2. Add the repeated content or functionality. To add a Help menu item, add a <do> element that contains a
<go> action that identifies the help page to be displayed:
By default, input fields begin on a new line. Text fields span the width of the browser window. To limit the
number of characters that users can type, use the maxlength attribute.
2. Add an stock symbol input field to the second card.
<p>
Product trading symbol: <input type="text" name="symbol"
format ="*AAA" />
</p>
3. To specify the action that the card performs when the user submits the content, add a <go> tag inside the
primary <do> element that you created in the “Define the WML deck and cards” procedure. In this example, a
Perl script runs. In the following code, the <do> element exists already.
<do type="accept" label="Submit">
<go href="/cgi-bin/loginScript.pl" method="post">
<postfield name="name" value="$(loginID)"/>
<postfield name="password" value="$(password)"/>
</go>
56
5: Creating a WML page
</do>
Using the <do> element, instead of <a> and <anchor> tags enables you to bind an action to the default
option for the page.
3. On the Page3 card, add two more option list. One will enable users to specify the notification trigger method,
the other will enable them to select what additional information will be pushed with the notification. The
second list is a multiple-selection list.
<p>
Notification trigger:
<select name="trigger" value="c">
<option value="c">Target price change</option>
<option value="r">Target high and low values</option>
</select>
</p>
<br/>
<p>
Include with push:
<select name="includes" multiple="true">
<option value="chart">Performance chart</option>
<option value="articles">Related articles</option>
</select>
</p>
Add an image
Use the <img> tag to include an image on the Help page. Place the image right-aligned in a new paragraph after
the Help page contents.
<p align="right" >
<!-- Adding an image with a link. -->
<a href="www.blackberry.com">
<img src="bb_power-wee.gif" height=20 alt="BlackBerry" />
</a>
</p>
57
BlackBerry Wireless Handheld Browser Content Developer Guide
• User-initiated events trigger actions when the user interacts with a screen element. You can use the following
events:
• onenterbackward: triggers an action to occur when the user enters the card by clicking <prev>
• onenterforward: triggers an action to occur when the user enters the card by clicking <go>
• onpick: triggers an action to occur when the user selects an option
• Timeline events trigger actions that occur at a certain point in time. A single event is available:
• ontimer: triggers an action to occur when the timer on a card expires
1. On the Help card, add an onpick event attribute to each option in the options list, so that the browser opens
the specified URL when the user selects the option.
<option value="rim" onpick="http://www.rim.com">
Research In Motion
</option>
<option value="blackberry" onpick="http://www.blackberry.com">
BlackBerry products
</option>
<option value="developers" onpick="http://www.blackberry.com">
BlackBerry Developer Zone
</option>
2. Modify the <card> element for the first card (Page1) to add a timer event, so that the Help card opens if the
user takes longer than 2 minutes to log in.
<card id="main" title="BlackBerry WML sample" ontimer="#help">
<timer value="2400"/>
Use the WML ontimer attribute to force new content to the browser after a specified amount of time has
passed.
The timer value is measured in tenths of a second, and the counter is reset when the page is refreshed. The
<timer> element is commonly used to redirect a WML page to another WML page; setting the value
attribute to 1 redirects the page automatically.
58
5: Creating a WML page
6. If the Target price change option was selected, display a dialog box that enables the user to specify the
amount by which the stock price must change to trigger a notification.
if(change) {
var valChange = Dialogs.prompt("Change value: ","");
var message = "You will be notified when the value changes by $"
+ valChange;
}
7. If the Target high/low value option was selected, display a dialog box that enables the user to specify a
target high, followed by a dialog box that enables the user to specify a target low.
if(range) {
var valHigh = Dialogs.prompt("High value: "."");
var valLow = Dialogs.prompt("Low value: ", "");
var message = "You will be notified when the value reaches a high of $"
+ valHigh + " or a low of $" + valLow;
}
8. Add a go event to the Page3 card that calls the setTriggers WMLScript function created in step 1.
<do type="accept" label="Next">
<go href="stock-monitor.wmls#setTriggers()"/>
</do>
Override a template
You might not want template elements to appear on every card in the deck. Use a technique called shadowing to
disable certain template elements on a card by adding the <noop> element. For example, you can disable the link
to the Help card on the Help card itself. To use the <noop> element to disable a soft key, first add the <do>
element that you want to deactivate, and then add the <noop> element.
1. On the Help card, after the <card> element, add the <do> element with the label="Help" attribute from
the template that you want to shadow.
<do type="help" label="Help" >
2. Instead of including the <go> element within the <do> element, use the <noop/> element. <noop/> tells the
browser to disable this option for this card.
<noop/>
59
BlackBerry Wireless Handheld Browser Content Developer Guide
</do>
Example: login.wml
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/
wml_1.1.xml">
<!--Copyright (C) 2004 Research In Motion Limited. All Rights Reserved -->
<!--loginScript.pl script, referenced in this example, is not shown here -->
<wml>
<template>
<do type="help" label="Help">
<go href="#Help"/>
</do>
</template>
<p>
Please enter your email address:
<input type="text" name="email" />
</p>
<p align="right" >
<!-- Adding an image with a link. -->
<a href="www.blackberry.com">
<img src="bb_power-wee.gif" height=20 alt="BlackBerry" />
</a>
</p>
</card>
60
5: Creating a WML page
<p>
Product trading symbol: <input type="text" name="symbol"
format ="*AAA" />
</p>
<p>
<!-- Creating a single selection list. -->
Listed on:
<select name="name" title="Listed on" value="TSE">
<option value="TSE">TSE</option>
<option value="NYSE">NYSE</option>
<option value="NASDAQ">NSADAQ</option>
<option value="Dow Jones">Dow Jones</option>
</select>
</p>
<p align="right" >
<!-- Adding an image with a link. -->
<a href="www.blackberry.com">
<img src="bb_power-wee.gif" height=20 alt="BlackBerry" />
</a>
</p>
</card>
61
BlackBerry Wireless Handheld Browser Content Developer Guide
$(message)
</p>
<br/>
<p align="right" >
<!-- Adding an image with a link. -->
<a href="www.blackberry.com">
<img src="bb_power-wee.gif" height=20 alt="BlackBerry" />
</a>
</p>
<do type="accept" label="Submit">
<go href="stock-monitor.php" method="post">
62
5: Creating a WML page
</wml>
Example: stock-monitor.wmls
function setTriggers() {
if(change) {
var valChange = Dialogs.prompt("Change value: ","");
var message = "You will be notified when the value changes by " + valChange;
}
if(range) {
var valHigh = Dialogs.prompt("High value: "."");
var valLow = Dialogs.prompt("Low value: ", "");
var message = "You will be notified when the value reaches a high of $"
+ valHigh + " or a low of $" + valLow;
}
63
BlackBerry Wireless Handheld Browser Content Developer Guide
64
6
Testing web pages
Using the simulators
Trackwheel
Home screen
Escape button
Backspace key
Alt key Enter key
Left Shift key Right Shift key
66
7
Creating browser push applications
Push applications
The Mobile Data Service push process
Mobile Data Service push applications
Writing Mobile Data Service push applications
Troubleshooting push applications
Push applications
Note: Push applications require BlackBerry Enterprise Server for Microsoft Exchange version 3.5 or later, or BlackBerry
Enterprise Server for IBM Lotus Domino version 2.2 or later, with the Mobile Data Service enabled.
Push applications enable you to send new web content and alerts to specific users. Users do not have to request or
download the data because the push application delivers the information as it becomes available.
There are two types of push applications:
• Browser push applications: Web content is sent to the browser on the handheld. The BlackBerry Browser
configuration supports Mobile Data Service push applications. WAP Browser configuration supports WAP
push applications. Push applications are not supported by the Internet Browser configuration.
• Client/server push applications: Data is sent to a custom Java application on the handheld. Client/server
push applications consist of a custom client application for the handheld and a server-side application that
pushes content to it. This approach provides more control over the type of content that you can send out and
how this data is processed and displayed on the handheld compared to browser push applications. See the
BlackBerry Applications Developer Guide Volume 1 -- Fundamentals, for information on writing custom Java
applications.
Server applications push content to handhelds by sending HTTP POST requests to the BlackBerry Enterprise Server.
The Mobile Data Service feature of the BlackBerry Enterprise Server forwards the content to the appropriate
handhelds, based on user email addresses. On the handheld, a separate browser push listener thread listens on
port 7874 for incoming messages and processes those messages.
The Mobile Data Service supports two push service implementations:
• RIM Push: Sends the push content as a byte stream to the destination user and port that is specified in the
URL of the push message. All push data is stored in RAM of the Mobile Data Service server.
• Push Application Protocol (PAP): Sends an HTTP POST request containing a PAP message. This message is a
MIME multipart message that includes an XML document specifying the control entity and the push content.
The control entity contains information about the destination handheld address, message ID, delivery time
stamps, and so on.
Push methods
Web content is pushed to the browser in one of the following ways:
• Message: Applications can push content pages to the handheld. Content pages appear as browser messages
in the handheld messages list. The message push request might include a descriptive title, which appears in
the messages list. Otherwise, the browser message displays the URL. Users open the browser message to view
the specified page in the browser.
Push applications can include the content in the browser message, so that the browser renders the pushed
content immediately in the handheld messages list. Alternatively, the application can include only the URL, so
that the browser performs a normal fetch operation to retrieve the content when the user requests it, either
from the local cache or from the network.
• Channel: Applications can push data to the handheld that create or update channels, which appear on the
handheld Home screen with a custom icon. Channels act as browser-based applications on the handheld for
regular updates of certain types of data.
A channel push request can include URLs for two icons:
• one to indicate that content is new or updated
• one to indicate that content has been read
These icons must be 28-by-28 pixel .png images. Depending on the handheld capabilities, content developers
can design monochrome or 16-color icons. The channel push message can specify the position on the Home
screen that the channel should occupy.
When the handheld receives a channel push message, it creates a new channel, or updates the channel if it
already exists. When a channel has been added or updated, an icon appears on the Home screen to alert users
that content is available. For example, an order-tracking channel could change the icon as product orders are
entered. Users click the icon to open an instance of the browser that displays the pushed content.
68
7: Push applications
Channel push requests include a channel identifier that uniquely describes the channel. Push applications can
delete a channel and remove the icon from the handheld Home screen by sending another push request with
the ID of the channel to delete.
Users can remove pushed channels from the Home screen.
Note: Deleting a channel removes only the instance of the channel that is currently stored on the handheld. If the
server pushes the channel again, it reappears on the Home screen.
• Cache — Applications can push content directly to the browser cache. Pushing content to the cache enables
users to access the content quickly, even when they are outside a wireless coverage area. Cache push content
can be associated with a channel. If a channel identifier is specified, the content URL is added to the
appropriate channel (if the channel is already active on the handheld) and to the persistent cache. Otherwise,
the content is added to the persistent cache only. There is no indication to the user that the content has been
updated. The next time that the user visits the specified URL, the browser retrieves the content from the
cache.
When an application pushes data to the browser cache, the application can include an expiry time that
defines how long the data remains in the cache before it is removed.
Reliable pushes
Push application developers can configure their push applications to provide acknowledgement upon the
successful delivery of a push submission. This enables them to verify that content has reached the handheld.
the following two levels of acknowledgement are available:
• Transport Level: In this case, a message is sent from the handheld acknowledging that the content has arrived
at the destination handheld. Transport level acknowledgment provides a guarantee that the data has been
delivered to the handheld; there is, however, no guarantee that the data has been delivered to the client
application.
Transport level acknowledgement is supported for all destination handhelds. If no acknowledgement level is
specified by the push application, transport level is assumed.
• Application Level: In this case, a message is sent after the content has reached the intended client
application.
Application level acknowledgement is only supported by those handhelds running version 4.0 of the
BlackBerry handheld software.
To maximize the reliability of push messages, push application developers can specify an Application Level
Acknowledgement Preferred setting, which uses application-level acknowledgements for those handhelds running
version 4.0 of the handheld software and transport-level acknowledgements for those handhelds that are not.
69
BlackBerry Wireless Handheld Browser Content Developer Guide
• Deliver-Before time-stamp: Enables push application developers to provide a time stamp before which the
push is required to be delivered. If a push is not successfully delivered by the specified time, the push is
considered to have failed.
The following additional tasks are supported by the PAP push service implementation only:
• Deliver-After time-stamp: Enables push application developers to provide a time stamp before which the push
must not be delivered. If a push is not successfully delivered after the specified time, the push is considered to
have failed.
• Push cancellation: Enables push applications to cancel a push submission that has already been sent.
• Push status query: Enables push applications to check the status of a push submission.
Push methods
Server applications push content to the handheld using one of three methods.
• Existing WAP connections: This option is only available when a WAP connection is open between the
handheld and the WAP gateway.
• SMS messages: If an existing WAP connection is not available, the service record provisioned for the GPRS and
CDMA networks typically uses SMS.
In addition, service providers can restrict incoming SMS messages to specific sources. The source address
restrictions are specified as parameters in the WAP Push service record that is sent during registration.
• UDP messages: If an existing WAP connection is not available, the service record provisioned for the iDEN
network typically uses UDP.
On the handheld, the WAP Push service record contains information on how the handheld can receive WAP
pushes. The service record also specifies on which ports the WAP Push Processor listens for incoming WAP Push
messages and how those incoming messages are handled.
70
7: The Mobile Data Service push process
By default both service indication and service loading messages are handled by the browser automatically. Users
can change how incoming push messages are handled or disable the browser push feature in the browser
configuration properties.
71
BlackBerry Wireless Handheld Browser Content Developer Guide
post/push?DESTINATION=<destination>&PORT=7874&REQUESTURI=<request_URI>
<header><content>
Note: The browser listens on port 7874.
2. The Mobile Data Service receives the HTTP request. It stores the destination and port information, and then
formats the request as follows:
post <request_URI><header><content>
3. If applicable, the Mobile Data Service applies a transcoder according to its transcoder rules.
The push request can override these rules to request a specific transcoder by using the transfer-encoding
header. For example, if the HTTP header transfer-encoding: vnd.wap.wml is set, the Mobile Data Service
runs the wml transcoder before it pushes the data to the handheld.
4. The Mobile Data Service sends the content to the handheld.
72
7: Mobile Data Service push applications
73
BlackBerry Wireless Handheld Browser Content Developer Guide
74
7: Writing Mobile Data Service push applications
The procedures that follow outline the general steps that are required to create push applications that create icons
on the handheld Home screen. When users click this icon, a web page appears. An example exists for each of the
Mobile Data Service push service implementations.
• See “Writing a RIM push application” on page 75 for an example of a RIM push application.
• See “Writing a PAP push application” on page 82 for an example of a PAP push application.
Complete sample code for each example is provided at the end of each section.
Note: You should push data based on users’ email addresses so that users continue to receive updates even if they
change handhelds or networks. Mobile Data Service provides the mapping between email addresses and handheld
PINs.
75
BlackBerry Wireless Handheld Browser Content Developer Guide
mdsConn.setRequestProperty("X-Rim-Push-Read-Icon-URL",
readIconUrl);
}
}
mdsConn.setRequestProperty("X-Rim-Push-Reliability", pushReliability);
mdsConn.setRequestProperty("X-Rim-Push-NotifyURL", notifyUrl);
mdsConn.setRequestProperty("X-Rim-Push-ID", pushId);
try {
mdsConn.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new RuntimeException("problems setting request method: " +
e.getMessage());
}
mdsConn.setAllowUserInteraction(false);
mdsConn.setDoInput(true);
mdsConn.setDoOutput(true);
5. Invoke the openConnection method on the URL to connect to the content server.
pushUrl = new URL(pushUrlString);
pushConn = (HttpURLConnection)pushUrl.openConnection();
6. Set properties for the HTTP GET request to the content server.
pushConn.setAllowUserInteraction(false);
pushConn.setDoInput(true);
pushConn.setDoOutput(false);
pushConn.setRequestMethod("GET");
7. Open the connection to the content server.
pushConn.connect();
8. Set properties for the HTTP POST request to Mobile Data Service. Copy the header properties from the GET
request and then set additional properties for the push.
String name;
String value;
for (int i = 0; true; i++) {
name = pushConn.getHeaderFieldKey(i);
value = pushConn.getHeaderField(i);
if ((name ==null) && (value == null)) { break; }
if ((name ==null) || (value == null)) { continue; }
if (name.equals("X-Rim-Push-Type")) { continue; }
if (name.equals("Transfer-Encoding")) { continue; }
System.out.println("setting header property " + name + "= " + value);
mdsConn.setRequestProperty(name, value);
}
9. Read content from the content server connection and write it to Mobile Data Service connection.
InputStream ins = pushConn.getInputStream();
OutputStream outs = mdsConn.getOutputStream();
copyStreams(ins, outs);
Tip: This step is optional for applications that use the channel or message push methods. If you do not push content to
the handheld, the browser fetches the content when the user requests it.
If you are pushing content to many users, copy the content to a temporary file to avoid multiple requests to the content
server.
76
7: Writing Mobile Data Service push applications
Create a method that reads a property file and pushes the page
1. Define the method that accepts an array of arguments.
public static void main(String[] args) {
2. Read values from the property file.
Properties prop = new Properties();
try {
prop.load(new FileInputStream(PROPERTIES_FILE));
}catch (FileNotFoundException fnfe) {
throw new RuntimeException("property file not found: " + fnfe.getMessage());
} catch (IOException ioe) {
throw new RuntimeException("problems reading property file: " +
ioe.getMessage());
}
3. Invoke the pushPage method that you created in “Write a push method” on page 75.
pushPage(mdsHostName, mdsPort, email, pushUrlString, pushType, pushTitle,
unreadIconUrl, readIconUrl, pushReliability, notifyUrl, PushId);
77
BlackBerry Wireless Handheld Browser Content Developer Guide
3. Edit the rim_browserpush.properties file to specify the location and names of the files to push to the
handheld.
4. Start the Mobile Data Service and handheld simulators.
5. Enable Mobile Data Service push functionality in the handheld simulator.
6. Compile and run the java file.
In the handheld simulator, the icon that is specified in the unreadIconUrl property appears on the handheld
Home screen. Click the icon to view the web page that is specified in the pushUrlString property.
/*
* BrowserChannelPush.java
* Copyright (C) 2004 Research In Motion Limited. All rights reserved.
*/
package com.rim.docs.samples.browserchannelpush;
import java.net.*;
import java.io.*;
import java.util.*;
public BrowserChannelPush() { }
/* Main method to read in property file and invoke the push method. */
78
7: Writing Mobile Data Service push applications
// The host name and port of Mobile Data Service to perform the push.
String mdsHostName = prop.getProperty("mdsHostName");
int mdsPort = (new Integer(prop.getProperty("mdsPort"))).intValue();
/* Two HttpURLConnections are used. One connects to the URL of the page to
* push and reads the page from there. The other connects to the BlackBerry
* Enterprise Server and writes the page to the server for pushing to the
* handheld.
*/
HttpURLConnection pushConn;
HttpURLConnection mdsConn;
URL pushUrl;
URL mdsUrl;
try {
mdsUrl = new URL("http", mdsHostName, mdsPort, "push?DESTINATION=" + email +
"&PORT=7874&REQUESTURI=/");
79
BlackBerry Wireless Handheld Browser Content Developer Guide
mdsConn = (HttpURLConnection)mdsUrl.openConnection();
mdsConn.setRequestProperty("Content-Location", pushUrlString);
mdsConn.setRequestProperty("X-RIM-Push-Title", pushTitle);
mdsConn.setRequestProperty("X-RIM-Push-Type", pushType);
if (pushType.equals(CHANNEL) || pushType.equals(CHANNEL_DELETE)) {
mdsConn.setRequestProperty("X-RIM-Push-Channel-ID", pushUrlString);
if (pushType.equals(CHANNEL)) {
mdsConn.setRequestProperty("X-RIM-Push-UnRead-Icon-URL", unreadIconUrl);
mdsConn.setRequestProperty("X-RIM-Push-Read-Icon-URL", readIconUrl);
}
}
mdsConn.setRequestProperty("X-RIM-Push-Reliability", pushReliability);
mdsConn.setRequestProperty("X-RIM-Push-NotifyURL", notifyUrl);
mdsConn.setRequestProperty("X-RIM-Push-ID", pushId);
try {
mdsConn.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new RuntimeException("problems setting request method: " +
e.getMessage());
}
mdsConn.setAllowUserInteraction(false);
mdsConn.setDoInput(true);
mdsConn.setDoOutput(true);
if (!pushType.equals(CHANNEL_DELETE)) {
//no need to connect to the pushed page for deletion
try {
pushUrl = new URL(pushUrlString);
} catch (MalformedURLException e) {
throw new RuntimeException("invalid push URL: " + e.getMessage());
}
pushConn = (HttpURLConnection)pushUrl.openConnection();
pushConn.setAllowUserInteraction(false);
pushConn.setDoInput(true);
pushConn.setDoOutput(false);
pushConn.setRequestMethod("GET");
pushConn.connect();
String name;
String value;
80
7: Writing Mobile Data Service push applications
mdsConn.setRequestProperty(name, value);
}
/*
* Read content from the push connection and write it to the
* MDS connection.
*/
/* Method to read data from the input stream and copy it to the output stream. */
private static void copyStreams(InputStream ins, OutputStream outs)
throws IOException {
int maxRead = 1024;
byte [] buffer = new byte[1024];
int bytesRead;
for(;;) {
bytesRead = ins.read(buffer);
if (bytesRead <= 0) {break;}
outs.write(buffer, 0, bytesRead);
}
}
}
# rim_browserpush.properties file
# Push from Mobile Data Service simulator on the local computer to handheld simulator.
mdsHostName = localhost
#pushType = Browser-Content
81
BlackBerry Wireless Handheld Browser Content Developer Guide
#pushType = Browser-Message
pushType = Browser-Channel
#pushType = Browser-Channel-Delete
pushTitle = Have a Great Day!
82
7: Writing Mobile Data Service push applications
}
String boundary = "";
if ((command == 'p') || (command == 'r')) {
boundary = "asdlfkjiurwghasf";
mdsConn.setRequestProperty("Content-Type", "multipart/related;
type=\"application/xml\"; boundary=" + boundary);
mdsConn.setRequestProperty("X-Wap-Application-Id", "/");
mdsConn.setRequestProperty("X-Rim-Push-Dest-Port", "7874");
}
else {
mdsConn.setRequestProperty("Content-Type", "application/xml");
}
mdsConn.setRequestProperty("Content-Location", pushUrlString);
mdsConn.setRequestProperty("X-RIM-Push-Title", pushTitle);
mdsConn.setRequestProperty("X-RIM-Push-Type", pushType);
if (pushType.equals(CHANNEL) || pushType.equals(CHANNEL_DELETE)) {
mdsConn.setRequestProperty("X-RIM-Push-Channel-ID", pushUrlString);
if (pushType.equals(CHANNEL)) {
mdsConn.setRequestProperty("X-RIM-Push-UnRead-Icon-URL", unreadIconUrl);
mdsConn.setRequestProperty("X-RIM-Push-Read-Icon-URL", readIconUrl);
}
}
try {
mdsConn.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new RuntimeException("problems setting request method: " +
e.getMessage());
}
mdsConn.setAllowUserInteraction(false);
mdsConn.setDoInput(true);
2. Define variables for connections to two URLs: one to the server with the content and one to Mobile Data
Service.
HttpURLConnection pushConn = null;
URL pushUrl;
83
BlackBerry Wireless Handheld Browser Content Developer Guide
3. Invoke the openConnection method on the URL to connect to the content server.
StringBuffer contentHeaders = new StringBuffer();
try {
pushUrl = new URL(pushUrlString);
} catch (MalformedURLException e) {
throw new RuntimeException("invalid push URL: " + e.getMessage());
}
pushConn = (HttpURLConnection)pushUrl.openConnection();
4. Set properties for the HTTP GET request to the content server.
pushConn.setAllowUserInteraction(false);
pushConn.setDoInput(true);
pushConn.setDoOutput(false);
pushConn.setRequestMethod("GET");
5. Open the connection to the content server.
pushConn.connect();
6. Set properties for the HTTP POST request to Mobile Data Service. Copy the header properties from the GET
request and then set additional properties for the push.
String name, value;
for (int i = 0; true; i++) {
name = pushConn.getHeaderFieldKey(i);
value = pushConn.getHeaderField(i);
if ((name ==null) && (value == null)) { break; }
if ((name ==null) || (value == null)) { continue; }
if (name.equals("X-RIM-Push-Type")) { continue; }
if (name.equals("Transfer-Encoding")) { continue; }
contentHeaders.append("\r\n").append(name).append(": ").append(value);
}
content[0] = contentHeaders.toString();
7. Read content from the content server connection and write it to Mobile Data Service connection.
InputStream ins = pushConn.getInputStream();
ByteArrayOutputStream bouts = new ByteArrayOutputStream();
copyStreams(ins, bouts);
ins.close();
content[1] = new String(bouts.toByteArray());
return content;
Tip: This step is optional for applications that use the channel or message push methods. If you do not push content to
the handheld, the browser fetches the content when the user requests it.
If you are pushing content to many users, copy the content to a temporary file to avoid multiple requests to the content
server.
Create a method that reads a property file and pushes the page
1. Define the method that accepts an array of arguments that includes the PAP command and PushID.
public static void main(String[] args) {
84
7: Writing Mobile Data Service push applications
2. Configure the method to send a different XML file based on the PAP command issued.
char command = args[0].charAt(0);
String papFilename;
switch (command)
{
case 'p':
papFilename = "pap_push.txt";
break;
case 's':
papFilename = "pap_status.txt";
break;
case 'c':
papFilename = "pap_cancel.txt";
break;
case 'r':
papFilename = "pap_replace.txt";
break;
default:
System.out.println("invalid command");
return;
}
3. Read values from a property file.
Properties prop = new Properties();
try {
prop.load(new FileInputStream(PROPERTIES_FILE));
} catch (FileNotFoundException fnfe) {
throw new RuntimeException("property file not found: " + fnfe.getMessage());
} catch (IOException ioe) {
throw new RuntimeException("problems reading property file: " +
ioe.getMessage());
}
if (useHttps == true) {
System.setProperty("javax.net.ssl.trustStore",
"C:\\p4\\main\\IPProxyProject\\webserver\\webserver.keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
}
85
BlackBerry Wireless Handheld Browser Content Developer Guide
if (command == 'r') {
System.out.print("Enter push id to replace: ");
replaceId = (new BufferedReader(new
InputStreamReader(System.in))).readLine().trim();
}
4. Invoke the getContent method that you created in “Create a method to retrieve the content” on page 83 to
retrieve the content.
String[] content = null;
if ((command == 'p') || (command == 'r')) {
content = getContent(pushUrlString, pushType, pushTitle, unreadIconUrl,
readIconUrl);
}
5. Invoke the pushPage method that you created in “Write a push method” on page 82.
pushPage(command, pushId, replaceId, papFilename, mdsHostName, mdsPort, pushType,
user, password, useHttps, content);
2. Deploy the web content and push icons that you want to push to handhelds on a web application server.
3. Place the BrowserChannelPush.java, pappush_browserpush.properties, pap_push.txt, pap_replace.txt,
pap_status.txt, and pap_cancel.txt files into a com\rim\docs\samples\browserpushdemo folder that is in
your CLASSPATH.
4. Edit the pap_browserpush.properties file to specify the location and names of the files to push to the
handheld.
86
7: Writing Mobile Data Service push applications
/*
* BrowserPushDemo.java
* Copyright (C) 2004 Reasearch In Motion Limited. All rights reserved.
* PAP Push properties file
*/
// package com.rim.samples.server.browserpushdemo;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import javax.net.ssl.*;
import sun.misc.BASE64Encoder;
/**
* Application which pushes a specified web page to a specified device.
*/
public class BrowserPushDemo {
public BrowserPushDemo() { }
/**
* Main method which reads the property file and performs the push.
*/
87
BlackBerry Wireless Handheld Browser Content Developer Guide
String papFilename;
switch (command)
{
case 'p':
papFilename = "pap_push.txt";
break;
case 's':
papFilename = "pap_status.txt";
break;
case 'c':
papFilename = "pap_cancel.txt";
break;
case 'r':
papFilename = "pap_replace.txt";
break;
default:
System.out.println("invalid command");
return;
}
// Hostname and Port of the Mobile Data Service that will perform the push.
String mdsHostName = prop.getProperty("mdsHostName").trim();
int mdsPort = (new Integer(prop.getProperty("mdsPort").trim())).intValue();
//Authentication properties.
String user = prop.getProperty("user");
String password = prop.getProperty("password");
// Push security?
boolean useHttps = false;
try {
useHttps = Boolean.valueOf(prop.getProperty("useHttps")).booleanValue();
} catch (Exception e) { }
if (useHttps == true) {
System.setProperty("javax.net.ssl.trustStore",
"C:\\p4\\main\\IPProxyProject\\webserver\\webserver.keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
}
88
7: Writing Mobile Data Service push applications
/*
* A method used to set the push connection and pass push content to
* the Mobile Data Service.
*/
private static String[] getContent(String pushUrlString, String pushType, String
pushTitle, String unreadIconUrl, String readIconUrl) {
String[] content = new String[2];
HttpURLConnection pushConn = null;
URL pushUrl;
StringBuffer contentHeaders = new StringBuffer();
try {
pushUrl = new URL(pushUrlString);
} catch (MalformedURLException e) {
throw new RuntimeException("invalid push URL: " + e.getMessage());
}
pushConn = (HttpURLConnection)pushUrl.openConnection();
pushConn.setAllowUserInteraction(false);
pushConn.setDoInput(true);
pushConn.setDoOutput(false);
pushConn.setRequestMethod("GET");
pushConn.connect();
contentHeaders.append("Content-Location: ").append(pushUrlString);
contentHeaders.append("\r\nX-RIM-Push-Title: ").append(pushTitle);
contentHeaders.append("\r\nX-RIM-Push-Type: ").append(pushType);
89
BlackBerry Wireless Handheld Browser Content Developer Guide
if (pushType.equals(CHANNEL) || pushType.equals(CHANNEL_DELETE)) {
contentHeaders.append("\r\nX-RIM-Push-Channel-ID: ").append(pushUrlString);
if (pushType.equals(CHANNEL)) {
contentHeaders.append("\r\nX-RIM-Push-UnRead-Icon-URL: ").append(unreadIconUrl);
contentHeaders.append("\r\nX-RIM-Push-Read-Icon-URL: ").append(readIconUrl);
}
}
/*
* Read the header properties from the push connection and write
* them to the Mobile Data Service connection.
*/
String name, value;
for (int i = 0; true; i++) {
name = pushConn.getHeaderFieldKey(i);
value = pushConn.getHeaderField(i);
if ((name ==null) && (value == null)) { break; }
if ((name ==null) || (value == null)) { continue; }
if (name.equals("X-RIM-Push-Type")) { continue; }
if (name.equals("Transfer-Encoding")) { continue; }
contentHeaders.append("\r\n").append(name).append(": ").append(value);
}
content[0] = contentHeaders.toString();
/*
* Read content from the push connection and write them to the
* Mobile Data Service connection.
*/
InputStream ins = pushConn.getInputStream();
ByteArrayOutputStream bouts = new ByteArrayOutputStream();
copyStreams(ins, bouts);
ins.close();
content[1] = new String(bouts.toByteArray());
return content;
}
public static void pushPage(char command, String pushId, String replaceId, String filename,
String mdsHostName, int mdsPort, String pushType, String user, String
password, boolean useHttps, String[] content) {
HttpURLConnection mdsConn;
URL mdsUrl;
try {
/* Push listener thread on the device listens to port 7874 for pushes from the
Mobile Data Service. */
String protocol = "http";
if (useHttps == true) {
protocol += "s";
}
mdsUrl = new URL(protocol, mdsHostName, mdsPort, "/pap");
mdsConn = (HttpURLConnection)mdsUrl.openConnection();
if ((user != null) && (password != null)) {
String authString = user + ":" + password;
mdsConn.setRequestProperty("Authorization", "Basic " + new
BASE64Encoder().encode(authString.getBytes()));
}
90
7: Writing Mobile Data Service push applications
mdsConn.setRequestProperty("Content-Location", pushUrlString);
mdsConn.setRequestProperty("X-RIM-Push-Title", pushTitle);
mdsConn.setRequestProperty("X-RIM-Push-Type", pushType);
if (pushType.equals(CHANNEL) || pushType.equals(CHANNEL_DELETE)) {
mdsConn.setRequestProperty("X-RIM-Push-Channel-ID", pushUrlString);
if (pushType.equals(CHANNEL)) {
mdsConn.setRequestProperty("X-RIM-Push-UnRead-Icon-URL", unreadIconUrl);
mdsConn.setRequestProperty("X-RIM-Push-Read-Icon-URL", readIconUrl);
}
}
try {
mdsConn.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new RuntimeException("problems setting request method: " +
e.getMessage());
}
mdsConn.setAllowUserInteraction(false);
mdsConn.setDoInput(true);
if (!pushType.equals(CHANNEL_DELETE)) {
mdsConn.setDoOutput(true);
OutputStream outs = mdsConn.getOutputStream();
InputStream ins = new BufferedInputStream(new FileInputStream(filename));
ByteArrayOutputStream bouts = new ByteArrayOutputStream();
copyStreams(ins, bouts);
String output = new String(bouts.toByteArray());
output = output.replaceAll("\\$\\(pushid\\)", pushId);
if ((command == 'p') || (command == 'r') {
output = output.replaceAll("\\$\\(boundary\\)", boundary);
output = output.replaceAll("\\$\\(headers\\)", content[0]);
output = output.replaceAll("\\$\\(content\\)", content[1]);
}
if (command == 'r') {
output = output.replaceAll("\\$\\(replaceid\\)", replaceId);
}
output = output.replaceAll("\r\n", "EOL");
output = output.replaceAll("\n", "EOL");
output = output.replaceAll("EOL", "\r\n");
copyStreams(new ByteArrayInputStream(output.getBytes()), outs);
}
mdsConn.connect();
91
BlackBerry Wireless Handheld Browser Content Developer Guide
/**
* Reads data from the input stream and copies it to the output stream.
*/
for(;;) {
bytesRead = ins.read(buffer);
if (bytesRead <= 0) {break;}
outs.write(buffer, 0, bytesRead);
}
}
}
iterations=1
delay=0
debug=true
useHttps = false
# Push from Mobile Data Service simulator on the local computer to handheld simulator.
mdsHostName = localhost
#pushType = Browser-Content
#pushType = Browser-Channel
#pushType = Browser-Channel-Delete
pushType = Browser-Message
92
7: Writing Mobile Data Service push applications
# Authentication credentials.
user=pix
password=password
Example: pap_push.txt
--$(boundary)
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN"
"http://www.wapforum.org/DTD/pap_2.0.dtd"
[<?wap-pap-ver supported-versions="2.0"?>]>
<pap>
<push-message push-id="$(pushid)"
deliver-before-timestamp="2005-09-18T19:50:00Z"
ppg-notify-requested-to="http://localhost/
PAPResultNotificationTest.jsp">
<!-- modify address-value attribute as necessary -->
<address address-value="WAPPUSH=recipient1%40pappush.com%3A7874/[email protected]"/
>
<quality-of-service delivery-method="unconfirmed"/>
</push-message>
</pap>
--$(boundary)
$(headers)
$(content)
--$(boundary)--
Example: pap_replace.txt
--$(boundary)
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN"
"http://www.wapforum.org/DTD/pap_2.0.dtd">
<pap>
<push-message push-id="$(pushid)"
replace-push-id="$(replaceid)"
replace-method="pending-only"
ppg-notify-requested-to="http://localhost:8080/
PAPResultNotificationTest.jsp">
<!-- modify address-value attribute as necessary -->
<address address-value="WAPPUSH=recipient2%40pappush.com/[email protected]"/>
<address address-value="WAPPUSH=recipient3%40pappush.com/[email protected]"/>
93
BlackBerry Wireless Handheld Browser Content Developer Guide
<address address-value="WAPPUSH=recipient4%40pappush.com/[email protected]"/>
<quality-of-service delivery-method="preferconfirmed"/>
</push-message>
</pap>
--$(boundary)
$(headers)
$(content)
--$(boundary)--
Example: pap_cancel.txt
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN"
"http://www.wapforum.org/DTD/pap_2.0.dtd">
<pap>
<cancel-message push-id="$(pushid)">
</cancel-message>
</pap>
Example: pap_status.txt
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN"
"http://www.wapforum.org/DTD/pap_2.0.dtd">
<pap>
<statusquery-message push-id="$(pushid)"/>
</pap>
94
7: Troubleshooting push applications
should replicate the BlackBerry Directory Database (bbdir.nsf). See the BlackBerry Enterprise Server for IBM
Lotus Domino Handheld Management Guide for more information.
95
BlackBerry Wireless Handheld Browser Content Developer Guide
96
A
Extensible Hypertext Markup (XHTML)
language reference
XHTML Mobile Profile reference
WAP CSS reference
Structural elements
<body>
Indicates the start of the page body content.
Attribute Description
style Specifies an inline style definition.
title Describes the contents of the body element.
background Specifies an image to use as the background.
bgcolor Specifies the background color of the document.
link Specifies the color of text used to indicate text links.
text Specifies the text color used in the document.
xml:lang Declares the human language used by the element.
<head>
Contains information about the current document, such as title, keywords that might be useful to
search engines, and other data that is not considered document content. User agents do not
generally render elements that appear in the head as content. They might, however, make
information in the head available to users through other mechanisms.
Attribute Description
profile Ignored.
BlackBerry Wireless Handheld Browser Content Developer Guide
<html>
The root element of an HTML file.
Attribute Description
version Used for grouping only. Deprecated.
lang Ignored.
xmlns Ignored.
<title>
Provides a descriptive title, which appears at the top of the browser screen. This element must be
enclosed in the <head> tag.
<acronym>
Specifies that the enclosed text is an acronym. Text appears in normal font.
<address>
Specifies that the enclosed text is a mailing address. Text appears in normal font.
<b>
Specifies that enclosed text be displayed as bold.
<big>
Renders text in a larger font.
<blockquote>
Specifies that the enclosed text is part of a quotation. Text appears indented by one character space
and appears in normal font.
Attribute Description
cite Provides a URL citation to indicate the source of a quotation. The attribute value should be a URL
enclosed in quotation marks; the URL appears as an underlined link.
lang Ignored.
<br/>
Starts a new line. To be XHTML-MP–compliant, make sure the element is self-closing.
98
A: Extensible Hypertext Markup (XHTML) language reference
<center>
Horizontally centers the enclosed text.
<cite>
Specifies that enclosed text is a citation. Text appears in italic.
<code>
Specifies that enclosed text represents code. Text appears in a fixed-width font.
<dfn>
Specifies that enclosed text is a term definition. Text appears in italic.
<div>
Defines a block of text to which a specific presentation style might be applied.
Attribute Description
align Aligns content according to the align attribute. Only horizontal alignment is supported.
(align=”left”, align=“center”, or align=“right”)
<em>
Renders the enclosed text in italic.
<h1> to <h6>
Indicate a heading. Text in heading elements appears in bold. The <h1> element appears in the
largest font, with the font size decreasing for each successive heading level.
Attribute Description
align Aligns text horizontally. The following values are acceptable:
• align="left"
• align="right"
• align="center"
<hr/>
Renders a horizontal line. To be XHTML-MP–compliant, make sure the element is self-closing.
<i>
Renders the enclosed text in italic.
<kbd>
Represents keyboard input. Text appears in a fixed-width font.
99
BlackBerry Wireless Handheld Browser Content Developer Guide
<p>
Delimits a paragraph of text. Each <p> element starts on a new line.
Attribute Description
align Aligns text horizontally. The following values are acceptable:
• align="left"
• align="right"
• align="center"
<pre>
Formats the enclosed text preserving all spacing and new lines. It does not display text in a fixed-
width font.
<q>
Specifies that enclosed text is a quotation. Text appears in normal font.
Attribute Description
cite Provides a URL citation to indicate the source of a quotation. The attribute value should be a URL
enclosed in quotation marks; the URL appears as an underlined link.
<samp>
Designates enclosed text as sample output from programs, scripts, and so on. Text appears in a
fixed-width font.
<small>
Renders text in a smaller font.
<span>
Delimits an arbitrary portion of content to which to apply style, display, or event management.
<strong>
Specifies that enclosed text be displayed as bold.
<tt>
Specifies the enclosed text as teletype. Text appears in a fixed width font.
<u>
Renders the enclosed text as underlined.
<var>
Indicates a variable name, or a value that the user supplies. Text appears in italic.
100
A: Extensible Hypertext Markup (XHTML) language reference
Link elements
<a>
Indicates an active link.
Attribute Description
href Identifies the target of the link. The following link schemes are supported for the href attribute:
• http://
• mailto:
• tel:
• wtai:
• cti:
• dc:
• PIN:
Text appears as an underlined link. When users select the link, the browser, phone, or messages list
opens.
hreflang Specifies the language of the hyperlink reference.
name Specifies a name for the link. The browser remembers the location as a target for other links.
accesskey Ignored.
charset Specifies the character encoding used in the referenced document; the value must be the name of a
standard character set.
rel Specifies the relationship between the current page and the referenced document. For example,
“stylesheet”.
rev Provides text that describes a link relationship from the referenced target document to the source
document. Not displayed to the user.
style Specifies an inline style definition.
tabindex Ignored.
title Provides a descriptive title for the anchor.
type Specifies the content type of the referenced document; the value is a MIME encoding text, such as
"text/plain".
<link>
Provides an external reference to another document.
Attribute Description
href Specifies the target URL of the resource.
rel Specifies the relationship between the current page and the referenced document. For example,
“stylesheet”.
type Specifies the MIME type of the target URL.
List elements
<dd>
Specifies a definition description. Text appears as a normal paragraph following the <dt> element,
with the left margin indented one space to the right.
101
BlackBerry Wireless Handheld Browser Content Developer Guide
<dl>
Specifies a definition list and encloses one or more <dt> tags.
<dt>
Specifies a definition term. Text appears as a normal paragraph.
<li>
Specifies a list item. These elements appear with a bullet or number, depending on the enclosing
element (<div>, <ul>, or <ol>).
<ol>
Specifies an ordered (numbered) list. One or more <li> elements enclosed in an <ol> element
appear with sequential numbers. The first enclosed <li> element appears on a new line.
<ul>
Specifies an unordered (bulleted) list. One or more <li> elements enclosed in a <ul> element
appear with a bullet. The first enclosed <li> element appears on a new line.
Attribute Description
action This attribute provides a URI to which the form is submitted; this attribute is required.
method The form query is submitted as part of the GET or POST request.
enctype This attribute is ignored. Form data is encoded with the content type application/x-www-form-
urlencoded.
name Ignored.
style Ignored.
title Ignored.
102
A: Extensible Hypertext Markup (XHTML) language reference
<input/>
Defines a user input object. The browser renders <input> elements according to the value of the
type attribute.
Attribute Description
type The following input types are acceptable:
• type=“checkbox”: The element is rendered using a check box control. Check boxes can occur
anywhere in a form element.
• type=“hidden”: Hidden elements are not displayed, but are included when the form is
submitted.
• type=“password”: The browser displays an asterisk (*) for each character that the user types.
The actual value is included in encoded form data when the form is submitted.
• type=“radio”: The element is rendered using a radio control. Radio input elements can appear
anywhere in a form element.
• type=“reset”: The element appears as a button. Users click the button to reset the form values
to its original values. This does not affect other forms on the screen.
• type=“submit”: The element appears as a submit button.
• type=“text”: The element appears as a text input field.
• type=“img”: The associated image that appears is selectable.
The following input types are not supported:
• type=“file”
• type=“button”
maxlength Sets the maximum number of characters for input elements with type set to password or text.
size Specifies the width of the text field, in characters.
checked Supported if type=“checkbox”. If this attribute is included, the check box appears selected, and the
value of the check box is included when the form is submitted.
name Specifies the name of the check box group; it is required when type=“checkbox”.
value Specifies the value to send to the server if a particular check box is selected when the form is submitted;
it is required when type=“checkbox”.
<label>
Provides a descriptive label for one or more input elements in a form. The label element encloses a
text label and one or more <input> elements. The text label appears in the browser in normal text.
Attribute Description
title The title attribute is ignored.
<option>
Encloses the text of an option in a select list.
Attribute Description
selected Defines the option that is initially selected.
103
BlackBerry Wireless Handheld Browser Content Developer Guide
<select>
Denotes a select list. A select list can be a single-selection or a multiple-selection list. A select list
contains one or more option elements.
With single-selection lists, the option with the selected attribute set is selected by default;
otherwise, the first option in the list is selected by default.
With multiple-selection lists, option elements with the selected attribute set are selected by default;
otherwise, no options are selected.
Attribute Description
multiple Indicates that users are permitted to select more than one option. Rendered as a list of check boxes.
<textarea>
Denotes a multiline text entry field in a form. It can optionally contain plain text, which is displayed
to the user in the text area.
Attribute Description
rows Required. Specifies the vertical dimensions of the text area, in number of characters.
cols Required. Specify the horizontal dimensions of the text area, in number of characters.
name The name attribute provides plain text to display to the user inside the text area.
<table>
Specifies the start of a table; it encloses <thead> and <tbody>, or <caption> and <tr>.
Attribute Description
border Specifies the thickness of the border around the outside edges of the table and the inner borders of
the table cells.
cellpadding Specifies the number of pixels of white space to add between cells.
cellspacing Specifies the number of pixels of white space that is rendered between each adjacent cell.
width Sets the width of the table, either in pixels or as a percentage of the browser window.
<td>
Denotes a table cell.
Attribute Description
colspan Specifies the number of columns that the cell should span.
rowspan Specifies the number of rows that the cell should span.
align Specifies the horizontal alignment of the cell content.
104
A: Extensible Hypertext Markup (XHTML) language reference
Attribute Description
width Specifies the width of the cell, either in pixels or as a percentage of the table width.
<th>
Denotes a table heading cell. Text in the cell bold.
<tr>
Denotes a table row.
Attribute Description
align Specifies the horizontal alignment of the row content.
Image elements
<area/>
Defines each area of the image.
Attribute Description
shape Defines the shape of the link area. The following values are acceptable:
• shape=“circle”
• shape=“rect”
• shape=“polygon”
coords This attribute specifies the x and y co-ordinates for the link area. Co-ordinates are comma-delimited.
href This attribute specifies file name and location of the link.
<img/>
Defines an image. Monochrome handhelds support .png and .gif graphics only. With the BlackBerry
Browser, the Mobile Data Service converts .jpeg images to .png format for display on monochrome
handhelds.
Attribute Description
src The browser displays the image that is specified by the src attribute. This attribute is required.
alt Specifies the text that appears when an image is unavailable, provided the browser has been correctly
configured to display it.
usemap Specifies the location of the map element.
height Specifies the height of the image with the unit of measurement. For example, “10pt” or “6px”.
width Specifies the width of the image with the unit of measurement. For example, “10pt” or “6px”.
align Images are aligned horizontally according to the align attribute. The following values are acceptable:
• align=“left”
• align=“right”
Vertical alignment is ignored.
105
BlackBerry Wireless Handheld Browser Content Developer Guide
<map>
Creates an image map.
Attribute Description
name Identifies the image map. The value must match the corresponding usemap value specified for the
image.
Object elements
<object>
The browser supports embedded content such as PME (transcoded SVG) content, MIDI files, and
other HTML pages. The browser does not support embedding of applets. However, the browser only
displays embedded content if it has been properly configured to do so by the end user.
<param>
Defines a parameter for an object.
Meta information
<base>
Specifies an absolute URI that acts as the base URI for resolving relative URIs.
Attribute Description
href Specifies an absolute URI that acts as the base URI for resolving relative URIs.
<meta>
This element provides additional information about the document. If the meta element is included,
the content attribute is required.
Attribute Description
http-equiv Defines the shape of the link area. The following values are acceptable:
• refresh: Redirects the browser to the URL specified by the content attribute.
• expires: Specifies that the browser should remove the page from the cache after the number of
seconds specified by the content attribute.
Note: This tag should be used sparingly for pages intended for wireless browsing because it
increases user traffic on the wireless network and can increase the time it takes to display the page.
• cache-control: Indicates that cache control parameters have been set for the page, specified
by the content attribute.
106
A: Extensible Hypertext Markup (XHTML) language reference
Attribute Description
content Required. Sets the meta information for http-equiv. If:
• http-equiv=“refresh”: Specifies the URL to which the browser is redirected.
• http-equiv=“expires”: Specifies the number of seconds after which the page is removed from
the cache. A value of -1 indicates that the page is not cached, so that the browser requests and
downloads the page every time it is accessed.
• http-equiv=“cache-control”: Specifies how the page ise cached. The following values are
acceptable:
• Public: Page can be stored in public shared caches.
• Private: Page can be stored only in private caches.
• No-cache: Page can not be cached.
• No-store: Page can be cached but not archived.
Script references
<script>
Defines a script, such as a JavaScript.
Attribute Description
type Specifies the MIME type of the script.
language Deprecated.
Values Description
propert_list Specifies a whitespace-separated list of values for the background-attachment, background-
color, background-image, and background-repeat properties. For example
blockquote {background: red url("images/sand.gif") no-repeat center}
See the descriptions of the background-attachment, background-color, background-
image, and background-repeat properties for more information on valid values.
107
BlackBerry Wireless Handheld Browser Content Developer Guide
background-attachment
For background images that are set behind an entire document, as a property applied to the <body>
element, the background-attachment property determines whether a background image is fixed
and content scrolls across it, or whether the background scrolls with the content.
Values Description
fixed Indicates that the content scrolls, but the background image does not.
scroll Default. Indicates that the background image scrolls with the content.
background-color
Sets the background color of content and padding. If you set a background color, set the foreground
to a contrasting color, so that its content remains visible.
Values Description
color_value Any valid color. A valid color can be specified in the following ways:
• an RGB value (“250,239,111”)
• Hexidecimal notation (“#770aff" or "#70f" (equal to "#7700ff"))
• a valid textual color name (“red”)
transparent Default. Makes the background invisible, enables the color of the parent element to be seen.
background-image
Sets an image as a background pattern.
Values Description
URL Specifies the location of the image to be used for the background pattern.
none Default. No background pattern is used.
background-repeat
Defines whether the background image is repeated (tiled) to fill the display.
Values Description
repeat Default. The background image is tiled both horizontally and vertically.
repeat-x The background image is tiled horizontally and is left-aligned.
repeat-y The background image is tiled vertically and is vertically centered.
no-repeat The background image is not tiled and is vertically centered and left-aligned.
108
A: Extensible Hypertext Markup (XHTML) language reference
border
A shorthand property for setting the width, color, and style of the individual sides of the border.
Properties can be listed in any order.
Values Description
property_list Specifies a whitespace-separated list of values for the border-color, border-style, and
border-width properties. For example:
table {border: red solid thick}
See the descriptions of the border-color, border-style, and border-width properties for
more information on valid values.
Values Description
property_list Specifies a whitespace-separated list of values for the color, style, and width of the specified side of a
border. For example:
table {border-right: red solid thick}
See the descriptions of the border-color, border-style, and border-width properties for
more information on valid values.
Values Description
color_value Any valid color. A valid color can be specified in the following ways:
• an RGB value (“250,239,111”)
• Hexidecimal notation (“#770aff" or "#70f", which is equal to "#7700ff")
• a valid textual color name (“red”)
The default is the current foreground color of the element.
Values Description
none Default. The element has no border.
hidden A hidden border is used. Hidden borders have no width and they are ignored by the browser.
solid A solid line is used as a border for the element.
109
BlackBerry Wireless Handheld Browser Content Developer Guide
Values Description
width_value Specifies the width of the border. The values for these properties can be any integer with the unit of
measurement. For example, “10pt” or “6px”.
Possible units include em (ems), ex (x-height), px (pixels), in (inches), cm (centimeters), mm
(millimeters), pt (points), and pc (picas).
thin Sets the element border to the browser’s interpretation of a thin width.
medium Default. Sets the element border to the browser’s interpretation of a medium width.
thick Sets the element border to the browser’s interpretation of a thick width.
inherit Indicates that the element inherits the border width of the containing element.
border-color
A shorthand property for setting the color of all four borders.
Values Description
color_value Any valid color. A valid color can be specified in the following ways:
• an RGB value (“250,239,111”)
• Hexidecimal notation (“#770aff" or "#70f", which is equal to "#7700ff")
• a valid textual color name (“red”)
The default is the current foreground color of the element.
border-style
A shorthand property for setting the style of all four borders.
Values Description
none Default. The element has no border.
hidden A hidden border is used. Hidden borders have no width and they are ignored by the browser.
solid A solid line is used as a border for the element.
border-width
A shorthand property for setting the width of all four borders.
Values Description
width_value Specifies the width of the border. The value for this property can be any integer with the unit of
measurement. For example, “10pt” or “6px”.
Possible units include em (ems), ex (x-height), px (pixels), in (inches),
cm (centimeters), mm (millimeters), pt (points), and pc (picas).
thin Sets the element border to the browser’s interpretation of a thin width.
medium Default. Sets the element border to the browser’s interpretation of a medium width.
110
A: Extensible Hypertext Markup (XHTML) language reference
Values Description
thick Sets the element border to the browser’s interpretation of a thick width.
inherit Indicates that the element inherits the border-width property of the containing element.
color
Sets the foreground color. The foreground is the content of the element, typically text, but also the
rule drawn for the <hr/> element, the color of any border (unless you set another color with one of
the border properties), and so on.
Values Description
color_value Any valid color. A valid color can be specified in the following ways:
• an RGB value (“250,239,111”)
• Hexidecimal notation (“#770aff" or "#70f", which is equal to "#7700ff")
• a valid textual color name (“red”)
font
A shorthand property that sets the font-family, font-size, font-style, and font-weight for text.
Properties can be listed in any order.
Values Description
property_list Specifies a whitespace-separated list of values for the font-family, font-size, font-style,
and font-weight properties. For example:
p {font: italic bold "Times New Roman" 10px}
See the descriptions of the font-family, font-size, font-style, and font-weight
properties for more information on valid values.
font-family
Sets a specific or generic font for text.
Values Description
font_name A specific font family name, such as “Arial” or “Times New Roman”. Font names must be enclosed
in quotation marks.
generic_font A font keyword such as serif, sans-serif, cursive, monospace. Generic font keywords should
not be enclosed in quotation marks.
inherit Indicates that the element inherits the font-family property of the containing element.
font-size
Sets the size of a font, either in absolute or relative terms. Relative values are relative to the font size
of the element that contains the current element.
Values Description
size_value Any integer with the unit of measurement. For example, “10pt” or “6px”.
Possible units include em (ems), ex (x-height), px (pixels), in (inches),
cm (centimeters), mm (millimeters), pt (points), and pc (picas).
111
BlackBerry Wireless Handheld Browser Content Developer Guide
Values Description
absolute_size Renders text according to a browser standard.
Possible values include xx-small, x-small, small, medium, large, x-large, xx-large.
relative_size Renders text at a size relative to the standard font size of the element.
Possible values include smaller and larger.
inherit Indicates that the element inherits the font-size property of the containing element.
font-style
Sets the font “style” for text.
Values Description
normal Default. No font style is applied.
italic Uses a font with “italic” in its name or failing that, one with “oblique” in its name. Italic fonts are also
sometimes named “cursive” or “kursive.”
oblique Uses a font with “oblique” in its name or failing that, one with “italic” in its name. Oblique fonts are
also sometimes named “slanted” or “inclined.”
inherit Indicates that the element inherits the font-style property of the containing element.
font-weight
Sets the thickness of the font.
The browser uses a roman font for font-weight values from 100 to 400 and a bold font for values
500 to 900.
Values Description
weight_value Specifies the absolute weight of the font. Possible values include 100 (lightest), 200, 300, 400, 500,
600, 700, 800, 900 (heaviest).
normal Sets the font to standard font weight. Equivalent to 400 on the numerical scale.
bold Sets the font to standard bold weight. Equivalent to 700 on the numerical scale.
bolder Increases the font weight by one level on the numerical scale. If the font already had a weight
equivalent to 900, it remains 900.
lighter Decreases the font weight by one level on the numerical scale. If the font already had a weight
equivalent to 100, it remains 100.
inherit Indicates that the element inherits the font-weight property of the containing element.
height, width
Sets the height/width of the content.
Values Description
measure_value Specifies the height/width. The value of this property can be any integer with the unit of measurement.
For example, “10pt” or “6px”.
Possible units include em (ems), ex (x-height), px (pixels), in (inches),
cm (centimeters), mm (millimeters), pt (points), and pc (picas).
auto Adjusts the height/width of the element to fit the content.
inherit Indicates that the element inherits the height or width property of the containing element.
112
A: Extensible Hypertext Markup (XHTML) language reference
table-layout
Controls the layout of table cells, rows, and columns.
Values Description
fixed Specifies that the width of a cell is fixed to a specified width. In this case, the table layout does not
depend on the content.
For example, if a column is fixed to a width of 25 pts, any line of text that exceeds this length is broken
and continued on a new line.
auto Specifies that the width of the cell is adjusted to the content. In this case, the table layout depends on
the content.
For example, if a line of text is 40 pts in length, the cell is adjusted to a width of 40 pts plus any
specified margin width.
inherit Indicates that the element inherits the table-layout property of the containing element.
text-align
Sets the horizontal alignment of lines of text.
Values Description
left Default. Aligns text to the left margin.
right Aligns text to the right margin.
center Centers the text in the display.
inherit Indicates that the element inherits the text-align property of the containing element.
text-decoration
Sets underlining and blinking of text.
Values Description
none Default. No text decoration is applied.
underline Underlines the text.
blink Causes the text to blink.
inherit Indicates that the element inherits the text-decoration property of the containing element.
-wap-input-format
Sets an input mask for text input in a form.
To limit the number of characters users can type, specify a single-digit number before the character
tag. For example, “3X” requires the user to type a maximum of three symbolic, numeric, or
uppercase alphabetic characters.
To enable users to type an unlimited number of characters, specify an asterisk (*) before the
character tag. For example, “*a” enables the user to type any number of symbolic or lowercase
alphabetic characters.
113
BlackBerry Wireless Handheld Browser Content Developer Guide
To insert a character into the mask, use the syntax \c, replacing the c with the character that you
want to insert. This is useful for inserting, for example, a dash in a nine-digit area code.
Values Description
A Any symbolic or uppercase alphabetic character (no numbers).
a Any symbolic or lowercase alphabetic character (no numbers).
N Any numeric character (no symbols or alphabetic characters).
X Any symbolic, numeric, or uppercase alphabetic character (not changeable to lowercase).
x Any symbolic, numeric, or lowercase alphabetic character (not changeable to uppercase).
M Default. Any symbolic, numeric, or uppercase alphabetic character (changeable to lowercase). For
multiple character input, the user input automatically defaults to an uppercase first character.
m Any symbolic, numeric, or lowercase alphabetic character (changeable to uppercase). For multiple
character input, the user input automatically defaults to a lowercase first character.
-wap-input-required
Requires a user to type text, click a button, or click a menu item on a form.
Values Description
True Specifies that the user is required to supply input.
False Specifies that the user is not required to supply input.
-wap-marquee-dir
Controls whether content scrolls from left to right (ltr) or from right to left (rtl).
Note: This property requires that the selected element also has the display property set to the -wap-marquee value.
Values Description
ltr Scrolls content from left to right.
rtl Scrolls content from right to left.
-wap-marquee-loop
Controls how many times the marquee effect repeats.
Note: This property requires that the selected element also has the display property set to the -wap-marquee value.
Values Description
iterations Indicates the number of iterations the marquee effect performs. The value can be any integer. Setting
this value to 0 has the same effect as not setting the display property to
-wap-marquee.
infinite The marquee effect loops indefinitely.
114
A: Extensible Hypertext Markup (XHTML) language reference
-wap-marquee-speed
Controls the speed of the marquee effect.
Note: This property requires that the selected element also has the display property set to the -wap-marquee value.
Values Description
slow Scrolls text across the screen slowly.
normal Scrolls text across the screen at the standard scroll rate.
fast Scrolls text across the screen quickly.
-wap-marquee-style
Controls how content scrolls across the screen.
Note: This property requires that the selected element also has the display property set to the -wap-marquee value.
Values Description
scroll The content starts completely off one side of the screen and then scrolls across the screen until its
completely off the other side of the screen, then repeats.
slide The content starts completely off one side of the screen and then scrolls across the screen. Scrolling
stops when the first character reaches the other side of the screen.
alternate The content starts completely off one side of the screen, scrolls across the screen until its completely
off the other side of the screen, and then does the same thing in the reverse direction, then repeats.
115
BlackBerry Wireless Handheld Browser Content Developer Guide
<blockquote>
<h1> to <h6>
<fieldset>
<button>
<center>
<legend>
<blink>
<input>
<body>
<cite>
<code>
<font>
<form>
<big>
<dfn>
<dir>
<div>
<img>
<kbd>
<dd>
<dt>
<em>
<li>
<a>
<b>
<i>
background a
background-attachment a
background-color a a a a a a a b a a a a a a a a a a a a a a a a a
background-image a
background-repeat a
border a a a
border-bottom a a a
border-bottom-color a a a
border-bottom-style a a a
border-bottom-width a a a
border-color a a a
border-left a a a
border-left-color a a a
border-left-style a a a
border-left-width a a a
border-right a a a
border-right-color a a a
border-right-style a a a
border-right-width a a a
border-style a a a
border-top a a a
border-top-color a a a
border-top-style a a a
border-top-width a a a
border-width a a a
color a a a a a a a a a a a a a a a a a a a a a a a a a
font a a a a a a a a a a a a a a a a a a a a a a a a a
font-family a a a a a a a a a a a a a a a a a a a a a a a a a
font-size a a a a a a a a a a a a a a a a a a a a a a a a a
font-style a a a a a a a a a a a a a a a a a a a a a a a a a
font-weight a a a a a a a a a a a a a a a a a a a a a a a a a
height a a 1
table-layout
text-align a a a a a a a a a a a a a a a a a a a a a a a
text-decoration a a a a a a a a a a a a a a a a a a a a a a a a a
width a a 1
-wap-input-format 2
-wap-input-required 2
-wap-marquee-dir a
-wap-marquee-loop a
-wap-marquee-speed a
-wap-marquee-style a
1
Applies only to <input> elements where type is one of “button”, “submit”, or “reset”.
2
Applies only to <input> elements where type=“text”.
116
A: Extensible Hypertext Markup (XHTML) language reference
<optgroup>
<textarea>
<marquee>
<option>
<select>
<strike>
<strong>
<small>
<table>
<menu>
<samp>
<span>
<pre>
<sub>
<sup>
<var>
<ol>
<td>
<th>
<tr>
<tt>
<ul>
<p>
<s>
<u>
background a a a a
background-attachment
background-color a a a a a a a a a a a a a a a a a a a a a a a a a
background-image a a a a
background-repeat a a a a
border a a a a a
border-bottom a a a a a
border-bottom-color a a a a a
border-bottom-style a a a a a
border-bottom-width a a a a a
border-color a a a a a
border-left a a a a a
border-left-color a a a a a
border-left-style a a a a a
border-left-width a a a a a
border-right a a a a a
border-right-color a a a a a
border-right-style a a a a a
border-right-width a a a a a
border-style a a a a a
border-top a a a a a
border-top-color a a a a a
border-top-style a a a a a
border-top-width a a a a a
border-width a a a a a
color a a a a a a a a a a a a a a a a a a a a a a a a a
font a a a a a a a a a a a a a a a a a a a a a a a a a
font-family a a a a a a a a a a a a a a a a a a a a a a a a a
font-size a a a a a a a a a a a a a a a a a a a a a a a a a
font-style a a a a a a a a a a a a a a a a a a a a a a a a a
font-weight a a a a a a a a a a a a a a a a a a a a a a a a a
height
table-layout a
text-align a a a a a a a a a a a a a a a a a a a a a a
text-decoration a a a a a a a a a a a a a a a a a a a a a a a a a
width a a a
-wap-input-format a
-wap-input-required a
-wap-marquee-dir a
-wap-marquee-loop a
-wap-marquee-speed a
-wap-marquee-style a
117
BlackBerry Wireless Handheld Browser Content Developer Guide
118
B
Wireless Markup Language (WML) reference
WML reference
WML reference
The following table summarizes browser support for each WML element and its attribute(s). The browser
supports WML 1.3.
Structure elements
<access>
If specified, the browser compares the <access> element to the domain and path that are specified
in the <access> element to determine whether the user has the proper access to display the page. If
not, the browser displays an error message.
Attribute Description
domain Specifies the domain used to verify access privileges.
path Specifies the path used to verify access privileges.
<card>
Contains the entire card.
Attribute Description
title Displays the card title in the Title area of the screen.
newcontext If set to true, this attribute clears the variable in store.
ordered Ignored. All elements in a page are rendered.
onenterforward Opens the specified URL when the card is accessed using a <go> task.
onenterbackward Opens the specified URL when the card is accessed using a <prev> task.
ontimer Opens the specified URL when the timer has expired.
<head>
A container element for information on access control that applies to the entire deck (the collection
of all cards). See the <access> element.
<meta>
Not supported. The browser ignores any <meta> tags.
BlackBerry Wireless Handheld Browser Content Developer Guide
<template>
Specifies deck-level <do> or <onevent> items. These items are included in every card for the deck,
unless the card has a more specific <do> or <onevent> element that shadows those in the template.
The browser handles template attributes as though they are <onevent> definitions for the
corresponding events.
Attribute Description
onenterforward Treated as an onenterforward <onevent> element with a <go> action.
onenterbackward Treated as an onenterbackward <onevent> element with a <go> action.
ontimer Treated as an ontimer <onevent> element with a <go> action.
<wml>
Defines a wml deck.
<big>
Renders text in the next larger size of the current font, if available. Nesting of <big> and <small>
elements is respected.
<br>
Starts a new line.
<p>
Denotes a new paragraph and renders content according to the attributes.
For layout purposes, the <p> and <br/> elements are the same.
Attribute Description
align Specifies the position of the contents of the <p> element on screen.
mode Ignored. Content is always wrapped.
<em>
Renders text in italic in the current font, if available. Otherwise, the standard font is used.
<i>
Renders text in italic in the current font and size, if available. Otherwise, the standard font and size
is used.
120
B: Wireless Markup Language (WML) reference
<pre>
Not supported.
<small>
Renders text in the next smaller size of the current font, if available. The browser supports nesting of
big and small elements.
<strong>
Renders text in the bold font of the current size, if available. Otherwise, the standard font is used.
<u>
Underlines content enclosed in the <u> element in the current font and size, if available. Otherwise,
the standard font and size are used.
Link elements
<a>
Specifies a link to follow.
Attribute Description
href Specifies the target of the link. The browser substitutes any variable references from the WAP context.
title Ignored.
accesskey Ignored.
<anchor>
When the user moves the cursor over a character or image that is contained in the <anchor>
element, users can click the Follow Link menu item to perform the <go>, <prev>, or <refresh> task
that is associated with the <anchor> element.
Attribute Description
domain Specifies the domain used to verify access privileges.
path Specifies the path used to verify access privileges.
Table elements
<table>
Denotes a new table.
Attribute Description
title Ignored.
121
BlackBerry Wireless Handheld Browser Content Developer Guide
align Aligns the text in table columns according to the align value. This attribute is optional. The content of
each cell is left-aligned by default.
For example, align="LCR". Content in the first column is left-justified; content in the second column
is centered; and content in the third column is right-aligned.
columns Required. Specifies the number of columns in the table.
<tr>
Denotes a new table row.
<td>
Denotes a new table cell.
Image elements
<img>
Defines an image. When images are contained in <anchor> or <a> elements, users can select the
image.
Attribute Description
alt Specifies the text that appears when an image is unavailable, provided that the browser has been
correctly configured to display it. When the real image arrives, the real image replaces the alt
placeholder.
src Specifies the location of the image on the server.
localsrc Unsupported. The browser does not support <localsrc> images.
vspace Specifies the amount of white space to insert above and below the image.
hspace Specifies the amount of white space to insert to the left and right of the image.
align Not supported. Each image is displayed on its own line.
height Specifies the image height.
width Specifies the image width.
Event elements
<do>
Defines an event trigger. The <do> element can enclose the following task elements: <go>, <prev>,
<noop>, or <refresh>.
122
B: Wireless Markup Language (WML) reference
In the browser, <do> elements that are defined on a card appear both as menu items on the browser
menu and as “soft keys" in a non-scrolling area at the bottom of the screen.
Attribute Description
type Required. Specifies the type of <do> element. The <do> element type can be one of accept, help,
or prev. A <do> element of type accept appears first on the menu.
The type attribute also matches <do> elements in the deck template, when the name attribute is not
defined, for shadowing purposes.
label Specifies the label used for the associated menu item. If a label attribute is not included, a default name
is assigned to the menu item based on type.
name Matches <do> elements in the deck template for shadowing purposes.
optional <do> elements with the optional attribute set appear after other <do> elements on the menu.
<onevent>
Specifies how events are handled.
Attribute Description
type Required. Identifies the event to handle; it also matches <do> elements in the deck template for
shadowing.
The type attribute can have one of the following values:
• onenterbackward: Occurs when a user navigates backward to a card.
• onenterforward: Occurs when a user navigates forward to a card.
• onpick: Occurs when a user selects or clears an option.
• ontimer: Occurs when the timer, specified by the <timer> element, expires.
id Sets a unique name for the element.
<postfield>
Specifies name/value pairs that are included in the HTTP request. <postfield> elements must be
enclosed in a <go> element. Variable references in the name and value attributes of each
<postfield> element are replaced with appropriate values from the WAP context.
Attribute Description
name Required. Specifies the name of the variable to be passed to the server.
value Required. Specifies the value of the variable to be passed to the server.
id Sets a unique name for the element.
123
BlackBerry Wireless Handheld Browser Content Developer Guide
Task elements
<go>
Directs the browser to a specified URI. The browser sets any variables that are specified in <setvar>
elements within the <go> element, and includes any values that are specified in contained
<postfield> elements.
Attribute Description
href Specifies the target URI that the browser goes to.
sendreferer Specifies whether the URI is sent in the request. Valid values are yes or no.
method Specifies the request type. The browser supports both the GET and the POST methods of
sending requests.
enctype Ignored. The browser uses the default: application/x-www-form-urlencoded.
cache-control Forces page retrieval from the network instead of the cache. If this attribute is set to no-cache, a
flag is set on the request being sent to invalidate this page in the cache, if it is there, before
retrieving the page.
accept-charset Ignored. The browser uses the default: UTF-8.
<noop>
Specifies whether the browser effectively removes any <do> or <onevent> elements from the current
card.
<prev>
Directs the browser to a specified URI. The inclusion of the <prev> element in <do> elements affects
menu construction. The browser menu always contains at least one item that enables users to go
back in the navigation history.
If the current card does not contain any <do> elements with a <prev> task, by default the browser
creates a Back menu item. If the current card contains one or more <do> elements that contain
<prev> elements, the browser does not create a separate menu item and relies on the <do> elements
for that card to provide this behavior instead.
<refresh>
Refreshes any variables that are specified by the enclosed <setvar> element(s). If an event occurs
that has a <refresh> task, the browser first sets any variables that are specified in <setvar>
elements that are contained in the <refresh> element. It then refreshes the current page using the
updated WAP context.
124
B: Wireless Markup Language (WML) reference
Input elements
<fieldset>
Ignored. Enclosed elements are rendered as through the <fieldset> element did not exist.
<input>
Renders as a text field into which users can type text. If users type a value that is not consistent
with the restrictions specified by the attributes in the input element, the browser displays a warning
when users try to save the value.
Input boxes appear on a separate line from the surrounding text.
Attribute Description
name Specifies the name of the variable to set with any typed value.
type Specifies the type of information being collected. Valid values include text or password. If type is
set to password, the browser displays an asterisk (*) for each character that the user types.
value Specifies the initial value that is displayed in the input field when the card is first rendered. This value
is used only when the variable specified by the name attribute is not set already in the WAP Context.
If the variable is set, the current value of that variable is used instead.
format Specifies a mask. The browser checks that any text the user enters in the input field conforms to the
mask that is specified by this attribute. The following character tags define which characters can be
typed:
• A — Any symbolic or uppercase alphabetic character (no numbers).
• a — Any symbolic or lowercase alphabetic character (no numbers).
• N — Any numeric character (no symbols or alphabetic characters).
• X — Any symbolic, numeric, or uppercase alphabetic character (not changeable to lowercase).
• x — Any symbolic, numeric, or lowercase alphabetic character (not changeable to uppercase).
• M — Default. Any symbolic, numeric, or uppercase alphabetic character (changeable to lowercase).
For multiple character input, the user input autmatically defaults to an uppercase first character.
• m — Any symbolic, numeric, or lowercase alphabetic character (changeable to uppercase). For
multiple character input, the user input autmatically defaults to a lowercase first character.
Tips:
• To limit the number of characters users can type, specify a single-digit number before the character
tag. For example, “3X” requires the user to type a maximum of three symbolic, numeric, or
uppercase alphabetic characters.
• To enable users to type an unlimited number of characters, specify an asterisk (*) before the
character tag. For example, “*a” enables the user to type any number of symbolic or lowercase
alphabetic characters.
• To insert a character into the mask, use the syntax \c, replacing the c with the character that you
want to insert. This is useful for inserting, for example, a dash in a nine-digit area code.
emptyok Enables the user to leave the field blank.
size Specifies the size, in characters, of the input box.
maxlength Specifies the maximum length of text the user can type.
tabindex Ignored. Tabbing is not supported.
125
BlackBerry Wireless Handheld Browser Content Developer Guide
<optgroup>
Ignored. Options in a <select> element are rendered as a flat list on the screen.
<option>
Specifies an item in a <select> list. <option> elements are rendered in the manner specified by the
enclosing <select> list.
Attribute Description
value Specifies the value of the enclosing <select> variable, if the <select> element has a NAME
attribute.
title Ignored.
onpick Specifies the URI that the browser loads when the option is selected.
<select>
Presents a list to the user. Users can select one or more of the options.
Select lists are fully displayed on every card. Users can scroll through options. Single-selection lists
are rendered as radio buttons. Multiple-selection lists are rendered as check boxes.
See the <option> element for more information.
Attribute Description
title Ignored.
name Specifies the name of the variable that is set with the selection.
value Sets the default value of the variable.
iname Specifies the variable to be set with the (1-based) index of the selected option, according to the
specifications.
ivalue Sets the index(es) of the preselected option(s). Use this attribute only if the variable specified by iname
does not already have a value.
multiple Specifies whether the <select> element is rendered as a multiple-selection list with a set of check
boxes.
tabindex Ignored. Tabs are not supported.
Variable elements
<setvar>
Specifies a new value for a given variable in the WAP context. When a <go>, <prev>, or <refresh>
task is performed, the browser first looks for any associated <setvar> elements and then updates
the WAP context accordingly before running the task.
Attribute Description
name Sets the name of the variable.
value Sets the value of the variable.
126
B: Wireless Markup Language (WML) reference
<timer>
Specifies a timer for the current card. The browser implements card timers according to the WML
specifications. In particular, a <refresh> operation stops the timer, sets its corresponding variable to
the current timer value, performs the refresh, and then resets the timer and restarts it.
When the timer expires, the variable that is specified by the name attribute is set to 0 before any
<ontimer>tasks are run.
Attribute Description
name Specifies the variable name to be set with the timer value for card entry, exit, and timer-expire events.
value Specifies the initial timer value for on-card entry events.
127
BlackBerry Wireless Handheld Browser Content Developer Guide
128
C
JavaScript language reference
Using JavaScript
Supported JavaScript objects
Using JavaScript
The BlackBerry device browser supports JavaScript 1.0, 1.1, 1.2, 1.3, and small subsets of JavaScript 1.4 and 1.5.
Note: JavaScript is only supported on handhelds with at least 16 MB of memory.
On the BlackBerry device browser, users can enable or disable JavaScript. JavaScript can also be disabled through
an IT policy.
See “Scripting Basics” on page 197 for information on JavaScript reserved words and supported statements, and
operators and expressions.
Additional JavaScript resources can be found on the Internet.
Methods —
BlackBerry Wireless Handheld Browser Content Developer Guide
Navigator The Navigator object is designed to return information about the version of the BlackBerry Browser that 136
is being used. All its properties, which are read-only, contain information about different aspects of the
browser.
Properties appCodeName language plugins
appName mimeTypes userAgent
appVersion platform
Document The Document object provides access to the elements in an HTML page from within your script. This 142
includes the properties of every form, link, and anchor (and, where applicable, any subelements), as well
as global document properties such as background and foreground colors.
Properties alinkColor fgColor plugins
anchors formName referrer
applets forms tags
bgColor height title
classes ids URL
cookie images vlinkColor
domain lastModified width
embeds linkColor
Form The Form object enables you to access the elements of an HTML form that is used to collect information 150
from users.
Properties action length target
elements method
encoding name
Screen The Screen object returns information about the dimensions and color depth of the handheld display. 150
Properties availHeight availWidth pixelDepth
availLeft colourDepth width
availTop height
Methods —
130
C: JavaScript language reference
BlackBerry
The BlackBerry object defines the network read-only property, which is used to define the network on which the
BlackBerry communicates.
location
Acts a pointer to the blackberry.location object. This property is only supported by BlackBerry
devices running version 4.1 of the BlackBerry device software. This property is read-only.
Syntax blackberry.location
Parameters none
Returns A pointer to the blackberry.location object.
131
BlackBerry Wireless Handheld Browser Content Developer Guide
Example The following code fragment displays the current geographic co-ordinates of the
BlackBerry device:
document.write("The client BlackBerry device is currently
located at " + blackberry.location.latitude +
" degrees latitude and " +
blackberry.location.longitude +
" degrees longitude.");
network
Identifies the wireless network on which the handheld is communicating. This property is read-only.
Syntax blackberry.network
Parameters none
Returns A string identifying one of the following networks: Mobitex®, GPRS, CDMA, iDEN.
Example The following code fragment displays the value of network:
document.write("The client BlackBerry device is communicating
on the " + blackberry.network + " wireless
network.");
BlackBerry Location
The BlackBerry Location object is designed to provide access to Global Positioning System (GPS) location of the
BlackBerry device. The GPS location refers to the geographical co-ordinates, latitude and longitude, of the
BlackBerry device.
132
C: JavaScript language reference
GPSSupported
Returns whether or not the BlackBerry device supports GPS. This property is read-only.
Syntax blackberry.location.GPSSupported
Parameters none
Returns • Boolean true if the BlackBerry device supports GPS.
• Boolean false if the BlackBerry device does not support GPS.
Example The following code determines whether GPS is supported, then sets the GPS
location aid mode and refreshes the location:
if(blackberry.location.GPSSupported) {
blackberry.location.setAidMode(0);
blackberry.location.refreshLocation();
}
latitude
Provides the current latitude of the BlackBerry device. To ensure that the most accurate co-ordinate
is returned, you should call refreshLocation() first. This property is read-only.
Syntax blackberry.location.latitude
Parameters none
Returns The current latitude, in degrees, of the BlackBerry device. Positive values indicate
northern latitude; negative values indicate southern latitude.
Example The following code fragment displays the current geographic co-ordinates of the
BlackBerry device:
document.write("The client BlackBerry device is currently
located at " + blackberry.location.latitude +
" degrees latitude and " +
blackberry.location.longitude +
" degrees longitude.");
longitude
Provides the current longitude of the BlackBerry device. To ensure that the most accurate co-
ordinate is returned, you should call refreshLocation() first. This property is read-only.
Syntax blackberry.location.longitude
Parameters none
133
BlackBerry Wireless Handheld Browser Content Developer Guide
Returns The current longitude, in degrees, of the BlackBerry device. Positive values indicate
eastern longitude; negative values indicate western longitude.
Example The following code fragment displays the current geographic co-ordinates of the
BlackBerry device:
document.write("The client BlackBerry device is currently
located at " + blackberry.location.latitude +
" degrees latitude and " +
blackberry.location.longitude +
" degrees longitude.");
onLocationUpdate()
Registers a callback method that is called when the location is updated using refreshLocation().
Syntax blackberry.location.onLocationUpdate(method)
refreshLocation()
Requests an update of the BlackBerry device’s location.
Syntax blackberry.location.refreshLocation
Parameters none
Returns A string containing the current latitude and longitude, in degrees, of the BlackBerry
device.
Example The following code determines whether GPS is supported, then sets the GPS
location aid mode and refreshes the location:
if(blackberry.location.GPSSupported) {
blackberry.location.setAidMode(0);
blackberry.location.refreshLocation();
}
134
C: JavaScript language reference
setAidMode()
Specifies which method the BlackBerry device will use to obtain the GPS location. There are three
ways the device can obtain location information.
Syntax blackberry.location.setAidMode(aidMode)
Parameters aidMode Identifies the method used to obtain GPS location. The value for this
parameter may be one of:
• 0: Cellsite
• 1: Assisted
• 2: Autonomous
Example The following code determines whether GPS is supported, then sets the GPS
location method and refreshes the location:
if(blackberry.location.GPSSupported) {
blackberry.location.setAidMode(0);
blackberry.location.refreshLocation();
}
135
BlackBerry Wireless Handheld Browser Content Developer Guide
Navigator
The Navigator object is designed to return information about the version of the BlackBerry Browser that is being
used. All its properties, which are read-only, contain information about different aspects of the browser.
appCodeName
Provides the application code name. This property is read-only.
Syntax navigator.appCodeName
Parameters none
Returns A string specifying the code name of the browser. The value could depend on the
emulation mode.
Example The following code fragment displays the value of the appCodeName property:
document.write("The code name of this application is " +
navigator.appCodeName);
appName
Provides the name of the client browser. This property is read-only.
Syntax navigator.appName
Parameters None
Returns A string that specifies the name of the browser. In the case of the handheld, the
value is always "BlackBerry."
136
C: JavaScript language reference
Example The following code fragment displays the value of the appName property, which, in
the case of the handheld, will be BlackBerry:
document.write("The name of the client browser is " +
navigator.appName);
appVersion
Provides the version of the BlackBerry Browser.
This property is read-only.
Syntax navigator.appVersion
Parameters none
Returns A string that contains the version of the BlackBerry Browser (for example, "4.1.0").
Example The following code fragment displays version information for the Navigator:
document.write("The version of the BlackBerry Browser is " +
navigator.appVersion);
javaEnabled()
Tests whether or not Java is enabled.
Syntax navigator.javaEnabled()
Parameters none
Returns In the case of the BlackBerry Browser, always returns true.
Example The following code fragment runs the function doThis if Java is enabled; otherwise,
it runs the function doThat:
if (navigator.javaEnabled()) {
doThis();
}
else doThat();
language
Provides the two-letter language code that represents the default language translation of the
browser.
This property is read-only.
Syntax navigator.language
Parameters none
Returns A string that contains the two-letter language code (For example, "en").
137
BlackBerry Wireless Handheld Browser Content Developer Guide
Example The following code fragment displays the value of the language property:
document.write("The default language translation of the client
browser is " + navigator.language);
mimeTypes
Provides the MIME types supported by the client.
This property is read-only.
Syntax • navigator.mimeTypes[index]
• navigator.mimeTypes.length
Parameters index An integer that represents a MIME type contained in the array.
Properties length Specifies the number of MIME types that are supported by the
client.
Returns An array of supported MIME types.
Example The following code fragment displays the type, description, and suffixes properties
for each supported mime type on a client:
for (i=0; i < navigator.mimeTypes.length; i++) {
document.writeln("<TR VALIGN=TOP><TD>",i,"</TD>",
"<TD>",navigator.mimeTypes[i].type,"</TD>",
"<TD>",navigator.mimeTypes[i].desc,"</TD>",
"<TD>",navigator.mimeTypes[i].suffixes,"</TD>");
}
138
C: JavaScript language reference
plugins.refresh()
Syntax navigator.platform
Parameters none
Returns A string indicating the platform on which the browser is running. In the case of the
handheld, the value will always be "BlackBerry".
Example The following code fragment displays the value of the platform property, which, in
the case of the handheld, will be BlackBerry:
document.write("The name of the client browser is " +
navigator.platform):
Syntax navigator.plugins
Parameters None
Returns A string that specifies the name of the browser. In the case of the handheld, the
value is always "BlackBerry."
Example The following code fragment displays the value of the appName property, which, in
the case of the handheld, will be BlackBerry:
document.write("The name of the client browser is " +
navigator.appName):
Makes newly installed plugins available and updates relevent arrays such as the plugins array.
Syntax navigator.plugins.refresh(true|false)
Parameters true The method reloads all open documents that contain embedded
objects
false All open documents are not reloaded.
Returns An empty array.
Example The following code fragment refreshes arrays and reloads open documents that
contain embedded objects:
navigator.plugins.refresh(true);
preferences()
Queries the preferences of the handheld.
Syntax navigator.preferences(prefName[, setValue])
139
BlackBerry Wireless Handheld Browser Content Developer Guide
Parameters prefName The name of the preference whose value you want to retrieve. Valid
names include:
• general.always_load_images
• security.enable_java
• javascript.enabled
• browser.enable_style_sheets
• autoupdate.enabled
• network.cookie.cookieBehavior
• network.cookie.warnAboutCookies
taintEnabled()
Syntax navigator.savePreferences()
Parameters None
Returns A string that specifies the name of the browser. In the case of the handheld, the
value is always "BlackBerry."
Example The following code fragment displays the value of the appName property, which, in
the case of the handheld, will be BlackBerry:
document.write("The name of the client browser is " +
navigator.appName);
Parameters none
Returns In the case of the BlackBerry Browser, this method always returns Boolean false.
140
C: JavaScript language reference
Example The following code fragment runs the function doThis if data tainting is enabled;
otherwise, it runs the function doThat:
if (navigator.taintEnabled()) {
doThis();
}
else doThat();
userAgent
Extracts the user agent from the user-agent header of the HTTP header. The user agent is used by
servers to identify the client browser. This property is read-only.
Syntax navigator.userAgent
Parameters none
Returns A string that represents the current user agent.
Example The following code fragment displays user agent information for the client browser:
document.write("The value of navigator.userAgent is " +
navigator.userAgent);
For example, in the case of a BlackBerry Browser client, this property might return
BlackBerry7210/4.0.0 (handheld model 7210, running version 4.0.0 of the
BlackBerry software).
141
BlackBerry Wireless Handheld Browser Content Developer Guide
Document
The Document object provides access to the elements in an HTML page from within your script. This includes the
properties of every form, link, and anchor (and, where applicable, any subelements), as well as global document
properties such as background and foreground colors.
alinkColor
Provides the color that is used to identify active links in the document.
142
C: JavaScript language reference
Parameters none
Returns A string that represents the active link color. Colors can be represented as a string
literal (for example, "teal") or as a hexidecimal triplet (for example, "#0055FF").
Example The following code fragment returns the color that is used to identify active links in
the active document:
document.write("Active links in this document are represented
using the color " + document.alinkColor);
bgColor
Returns the color that is used for the background of the active document.
This property is read-only.
Syntax document.bgColor
Parameters none
Returns A string that represents the background color of the document. Colors can be
represented as a string literal (for example, "teal") or as a hexidecimal triplet (for
example, "#0055FF").
Example The following code fragment returns the color that is used as the background color
in the active document:
document.write("The background color of this document is " +
document.bgColor);
close()
Closes a previously opened output stream.
Syntax document.close()
Parameters none
143
BlackBerry Wireless Handheld Browser Content Developer Guide
Example The following code fragment calls document.close() to close a stream that was
opened with document.open(). The document.close() method forces the
content of the stream to display in the window.
function doThis() {
var string1 = "Hi mom!";
var string2 = "Bye mom!";
document.open();
document.write(string1 + "<P>" + string2);
document.close();
}
cookie
Provides a report that details all visible and unexpired cookies that are associated with the specified
document.
This is a writable property.
Syntax document.cookie
Parameters none
Returns A comma-separated list that contains the cookies for the active document.
Examples The following code fragment displays information about visible and unexpired
cookies:
document.write("The following cookies are associated with this
document:
document.writeln(document.cookie)
domain
Provides the domain of the server that served the active document.
This property is read-only.
Syntax document.domain
144
C: JavaScript language reference
Parameters none
Returns A string that contains the domain name of the server that served the document.
Example The following code fragment returns the domain name of the hosting server:
document.write("This document originated from the " +
document.domain + "domain.");
fgColor
Returns the color that is used for the foreground (the text) of the active document. This property is
read-only.
Syntax document.fgColor
Parameters none
Returns A string that represents the foreground text color. Colors can be represented as a
string literal (for example, "teal") or as a hexidecimal triplet (for example,
"#0055FF").
Example The following code fragment returns the text color that is used in the active
document:
document.write("The text color of this document is " +
document.fgColor);
formName
Provides a specific form in the active document, referring to it by the name attribute of the HTML
<form> tag. This property is read-only.
Syntax document.formName
Parameters formName Represents the value of the name attribute for the HTML <form>
tag.
Returns The form associated with the given formName.
Example The following code fragment submits a form called loginForm:
document.loginForm.submit();
145
BlackBerry Wireless Handheld Browser Content Developer Guide
forms
Provides a list of all the form objects in the active document. This property is read-only.
Syntax document.forms[index]
Parameters index An integer or string that represents a form that is contained in the
array.
Returns An array that contains references to all the forms found in the active document.
Example The following code fragment submits the first form in the forms array:
document.forms[0].submit();
lastModified
Extracts the date that the document was last modified from the HTTP header. This property is read-
only.
Syntax document.lastModified
Parameters none
Returns A string representing the date that the document was last modified.
Example In the following code fragment, lastModified is used in a <SCRIPT> tag at the
end of an HTML file to display the modification date of the page:
document.write("This page updated on " +
document.lastModified);
146
C: JavaScript language reference
linkColor
Returns the color that is used by the active document to identify hyperlinks. This property is read-
only.
Syntax document.linkColor
Parameters none
Returns A string that represents the link color. Colors can be represented as a string literal
(for example, "teal") or as a hexidecimal triplet (for example, "#0055FF").
Example The following code fragment returns the color that is used as the link color in the
active document:
document.write("Hyperlinks in this document are represented
using the color " + document.linkColor);
open()
Opens the output stream to the current document to collect data from the write() and writeln()
methods.
Syntax document.open()
Parameters none
Example The following code fragment calls document.close() to close a stream that was
opened with document.open(). The document.close() method forces the
content of the stream to display in the window.
function doThis() {
var string1 = "Hi mom!";
var string2 = "Bye mom!";
document.open();
document.write(string1 + "<P>" + string2);
document.close();
}
referrer
Provides the URL of the document through which the user arrived at the active document, if it
exists. This property is read-only.
Syntax document.referrer
Parameters none
147
BlackBerry Wireless Handheld Browser Content Developer Guide
Returns • If the user arrived at the active document from another document, a string that
contains the URL of the referring document is returned.
• If the user typed the URL or reached the active document through some other
means, an empty string is returned.
Example In the following code fragment, the getReferrer function is called from the active
destination document. It returns the URL of the source document:
function getReferrer() {
return document.referrer;
}
title
Retrieves or sets the title of the active document. This is a writable property.
Syntax document.title[="title"]
Parameters title The name of the document, as it appears in the title bar of the
BlackBerry Browser.
Returns A string that contains the title of the document, as specified by the <title>
element.
Example The following code fragment sets the title of the active document as "BlackBerry
Home Page":
document.title="BlackBerry Home Page";
URL
Retrieves or sets the complete URL of the active document. This property is read-only.
Syntax document.URL
Parameters none
Returns A string that contains the URL of the active document.
Example The following code fragment displays the URL of the current document:
document.write("The current URL is " + document.URL);
vlinkColor
Returns the color that is used by the active document to identify links previously visited by the user.
This property is read-only.
Syntax document.linkColor
Parameters none
148
C: JavaScript language reference
Returns A string that represents the visited link color. Colors can be represented as a string
literal (for example, "teal") or as a hexidecimal triplet (for example, "#0055FF").
Example The following code fragment returns the color that is used as the link color in the
active document:
document.write("Visited links in this document are represented
using the color " + document.vlinkColor);
write()
Writes HTML expressions to the specified document.
Syntax document.write(Expression1 [, Expression2, ...]);
In the following code fragment, write() takes two arguments to display the string
"Hello world...." The first argument is an assignment expression, and the
second argument is a string literal.
msgWindow.document.write(mystr = "Hello " + "world...");
In the following code fragment, the write method takes a single argument that is a
conditional expression. If the value of the variable age is less than 18, the method
displays "Minor." If the value of age is greater than or equal to 18, the method
displays "Adult."
msgWindow.document.write(status = (age >= 18) ? "Adult" :
"Minor");
writeln()
Writes HTML expressions to the specified document, and places a new line character at the end of
the expression.
Syntax document.writeln(Expression1 [, Expression2, ...]);
149
BlackBerry Wireless Handheld Browser Content Developer Guide
Example The following code displays the type, description, and suffixes properties for
each supported MIME type on a client:
for (i=0; i < navigator.mimeTypes.length; i++) {
document.writeln("<TR VALIGN=TOP><TD>",i,
"<TD>",navigator.mimeTypes[i].type,
"<TD>",navigator.mimeTypes[i].description
"<TD>",navigator.mimeTypes[i].suffixes);
}
Form
The Form object enables you to access the elements of an HTML form that is used to collect information from
users.
action
Accesses the action attribute of an HTML <form> element, which defines the URL to which the
form is submitted. This is a writable property.
Syntax formName.action[="serverURL"]
Parameters formName The form for which data is being submitted. This parameter can be
either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
serverURL The URL of the server to which form field input information is sent.
This parameter can specify a CGI or LiveWire application on the server;
it can also be a mailto: URL if the form is to be mailed.
150
C: JavaScript language reference
Returns A string that describes the URL to which the submits data, unless serverURL is
specified.
Example The following code fragment specifies that responses to the loginForm form are
displayed in the msgWindow window:
document.loginForm.action="urlName";
elements
Provides a list of the elements that are found in the form. This property is read-only.
Syntax • formName.elements[index]
• formName.elements.length
Parameters formName The form that contains the listed elements. This parameter can be
either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
index An integer that represents an object of the form, or the name of the
element object as specified by its name attribute.
Properties length See "length" on page 141 for more information.
Returns An array that contains each element of the form.
Example The following code fragment writes a list of the elements contained in the form
loginForm:
document.write("This form contains the following HTML
elements:");
for (i=0; i < loginForm.elements.length; i++) {
document.write(loginForm.elements[i]);
}
encoding
Specifies the value of the enctype attribute for the HTML <form> tag, which provides the MIME
encoding of the form. This property is read-only.
Syntax formName.encoding
151
BlackBerry Wireless Handheld Browser Content Developer Guide
Parameters formName The form for which the encoding type is being retrieved. This
parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
Returns A string that indicates the MIME encoding of the form.
Example The following function returns the value of the loginForm encoding property:
function getEncoding() {
return document.loginForm.encoding;
}
length
Specifies the number of elements in the form. This property is read-only.
Syntax • formName.length
• formName.elements.length
Parameters formName The form for which the number of elements is being retrieved. This
parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
Returns An integer that represents the number of elements of the form.
Example The following code fragment writes a list of the elements contained in the form
loginForm:
document.write("This form contains the following HTML
elements:");
for (i=0; i < loginForm.length; i++) {
document.write(loginForm.elements[i]);
}
152
C: JavaScript language reference
method
Returns the value of the method attribute of the HTML <form> element, which defines the method
used to submit the form data to the server. This property is read-only.
Syntax formName.method
Parameters formName The form for which the submit method is being queried. This
parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
Returns A string that represents the submit method. This string can have a value of either
GET or POST.
Example The following code fragment returns the submit method for the loginForm form:
document.write("This form submits data to the server using the
" + loginForm.method + " method");
name
Returns the value of the name attribute of the HTML <form> element, which provides the name of
specified form. This property is read-only.
Syntax formName.name
Parameters formName The form for which the value of the name attribute is being retrieved.
This parameter is an element in the document.forms array.
Returns An array that contains each element of the form.
Example The following code fragment writes a list of each of the forms found in the active
document:
document.write("This document contains the following HTML
forms:");
for (i=0; i < document.forms.length; i++) {
document.write(document.forms[i].name);
}
onClick
Specifies the event that follows when an object on click event occurs.
Syntax formName.onClick[="event"]
153
BlackBerry Wireless Handheld Browser Content Developer Guide
Parameters formName The name of the form. This parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
event The event that is performed.
Returns A string describing the event which has been previously set to occur when a form
object is clicked, unless event is specified.
Example The following code fragment shows an onclick event handler that calls the
function isValidAddress() when the Calculate button is clicked.
<INPUT TYPE="button" VALUE="Calculate"
onClick="compute(this.form)">
onReset
Specifies the event that follows a reset action.
Syntax formName.onReset[="event"]
Parameters formName The name of the form. This parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
event The event that is performed.
Returns A string describing the event which has been previously set to occur when the form
is reset, unless event is specified.
Example The following code fragment shows an onReset event handler that displays an alert
dialog informing the user that defaults have been reset.
<FORM NAME="form1" onSubmit="return isValidAddress()"
onReset="alert("Default values have been restored">
<B>Please enter your email address:</B>
<INPUT TYPE="text" NAME="address" SIZE=10><P>
<INPUT TYPE="submit" VALUE="Done" NAME="submit1">
<INPUT TYPE="reset" VALUE="Clear Form" NAME="Reset1">
</FORM>
onSubmit
Specifies the event that follows a submit action.
Syntax formName.onSubmit[="event"]
154
C: JavaScript language reference
Parameters formName The name of the form. This parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
event The event that is performed.
Returns A string describing the event which has been previously set to occur when the form
is submitted, unless event is specified.
Example The following code fragment shows an onSubmit event handler that calls the
function isValidAddress(), which determines whether the email address entered
is valid before the form data is submitted to the server.
<FORM NAME="form1" onSubmit="return isValidAddress()"
onReset="alert("Default values have been restored">
<B>Please enter your email address:</B>
<INPUT TYPE="text" NAME="address" SIZE=10><P>
<INPUT TYPE="submit" VALUE="Done" NAME="submit1">
<INPUT TYPE="reset" VALUE="Clear Form" NAME="Reset1">
</FORM>
reset()
Clears user input and resets the default values of the form.
Syntax formName.reset()
Parameters formName The name of the form to be reset. This parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
Example The following code fragment extracts data from the form located below. If the data
is not entered properly (for example, CA or AZ is not entered), the form is reset.
function isValidAddress(){
if (document.loginForm.address == .value == 'CA' ||
textObject.value == 'AZ') {
alert('Nice input');
}
else { document.loginForm.reset() }
155
BlackBerry Wireless Handheld Browser Content Developer Guide
submit()
Submits the specified form. This is equivalent to the user clicking a Submit button.
Syntax formName.submit()
Parameters formName The name of the form to be submitted. This parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
Example The following code fragment submits a form called loginForm:
document.loginForm.submit();
If loginForm is the first form you create, you also can submit it as follows:
document.forms[0].submit();
target
Sets or returns the target window that responses are sent to after a form is submitted.
Note: Because the BlackBerry Browser is a single document interface (that is, it never displays more than one browser
window at a time) setting a target essentially has no effect.
Parameters formName The name of the form to be submitted. This parameter can be either
• the value of the name attribute for the HTML <form> tag
• an element in the document.forms array
windowName The name of the window to which responses are sent.
Returns A string that represents the name of the target window.
Example The following code fragment specifies that responses to the loginForm form are
displayed in the msgWindow window:
document.loginForm.target="msgWindow";
Screen
The Screen object returns information about the dimensions and color depth of the handheld display.
156
C: JavaScript language reference
availHeight
Retrieves the height of the handheld screen. This property behaves identically to the height
property. This property is read-only.
Syntax screen.availHeight
Parameters none
Returns An integer that represents the screen height, in pixels.
Example The following code fragment returns the screen height:
document.write("The screen is " + screen.availHeight + " pixels
high.");
availWidth
Retrieves the width of the handheld screen. This property behaves identically to the width property.
This property is read-only.
Syntax screen.availWidth
Parameters none
Returns An integer that represents the screen width, in pixels.
Example The following code fragment returns the screen width:
document.write("The screen is " + screen.availWidth + " pixels
wide.");
colourDepth
Retrieves the bit depth of the color palette. This property behaves identically to the pixelDepth
property. This property is read-only.
Syntax screen.colourDepth
Parameters None
157
BlackBerry Wireless Handheld Browser Content Developer Guide
Returns • The bit depth of the hendheld color palette, if it uses one.
• If no palette is used, this property reflects the value of pixelDepth.
Example The following code fragment returns the bit depth of the color palette:
document.write("The handheld display has a pixel depth of " +
screen.colourDepth);
height
Retrieves the height of the screen height. This property behaves identically to the availHeight
property. This property is read-only.
Syntax screen.height
Parameters none
Returns An integer that represents the screen height, in pixels.
Example The following code fragment returns the screen height:
document.write("The screen is " + screen.height + " pixels
high.");
pixelDepth
Returns the bit depth of the palette. This property behaves identically to the colourDepth
property.This property is read-only.
Syntax screen.pixelDepth
Parameters none
Returns An integer that represents the color resolution, in bits per pixel, of the display.
Example The following code fragment returns the screen height:
document.write("The screen has a pixel depth of " +
screen.pixelDepth + " bits per pixel.");
width
Retrieves the width of the screen. This property behaves identically to the availWidth property.
This property is read-only.
Syntax screen.width
Parameters none
158
C: JavaScript language reference
159
BlackBerry Wireless Handheld Browser Content Developer Guide
Window
The Window object is created automatically when the browser encounters a <body> or <frame> tag, and returns
information about the window.
160
C: JavaScript language reference
alert()
Displays a standard alert dialog box with an OK button.
Syntax window.alert("message")
161
BlackBerry Wireless Handheld Browser Content Developer Guide
atob()
Decodes a given Base64 string.
Syntax window.atob(string)
back()
Displays the previous URL in the history list.
Syntax window.back()
Parameters none
Example The following code fragment adds a custom button to an HTML page that displays
the previous item in the history list:
<P><INPUT TYPE="button" VALUE="< Back" onClick="window.back()">
blackberry
Acts a pointer to the blackberry object. This property is read-only.
Syntax window.blackberry
Parameters none
Returns A pointer to the BlackBerry object.
Example The following code fragment displays the value of the network property:
document.write("The client BlackBerry handheld is communicating
on the " + window.blackberry.network + " wireless
network.");
162
C: JavaScript language reference
btoa()
Encodes a given string to Base64.
Syntax window.btoa(string)
clearInterval()
Clears a repeating timer.
Syntax window.clearInterval(intervalID)
Parameters intervalID The ID (specified when the interval timer was created using
setInterval()) of the interval to be cleared.
Example After users clicks the Start button, the following code fragment writes the given
string every five seconds (5,000 milliseconds). The user must click the Stop button
to cancel the timer and stop new lines from being written.
<input type="button" value="Start"
onclick="timerID=setInterval(document.writeln("the
timer is on"), 5000);" />
<input type="button" value="Stop"
onclick="timerID=clearInterval(timerID);" />
clearTimeout()
Clears a non-repeating timer.
Syntax window.clearTimeout(timeoutID)
Parameters timeoutID The identifier (set using setTimeout()) that specifies the timeout
evaluation that is cleared.
163
BlackBerry Wireless Handheld Browser Content Developer Guide
Example The following code fragment runs the displayAlert() function five seconds
(5,000 milliseconds) after the user clicks a button. If the user clicks the second
button before the message is displayed, the timeout is canceled and the message is
not displayed.
<INPUT TYPE="button" VALUE="5-second reminder"
NAME="remind_button"
onClick="timerID=setTimeout('displayAlert()',5000)"
>
<INPUT TYPE="button" VALUE="Clear the 5-second reminder"
NAME="remind_disable_button"
onClick="clearTimeout(timerID)">
close()
Closes the active window, going back one element in history.
Note: Because the BlackBerry Browser is a single document interface, there are no active or inactive windows; instead,
it stacks windows as successive items in the history list. If users close the current window, the previous document
appears. The only exception is when the current document is the first item in the history. In this case, closing the
window causes users to exit the browser.
Syntax window.close()
Parameters none
Example The following code fragment closes the active window and displays the previous
page in the history list:
window.close()
164
C: JavaScript language reference
confirm()
Displays a standard confirmation dialog box with an OK and Cancel button.
Syntax window.confirm("message")
defaultStatus
Defines the default message that is displayed in the status bar. You can override this message using
the status property. This is a writable property.
Syntax window.defaultStatus = "message"
Parameters message The message that is displayed by default in the status bar.
Example The following code fragment sets the default status message:
window.defaultStatus = "Click the link to go to the BlackBerry
homepage.";
document
Specifies the Document object that is contained within the window. This property is read-only
Syntax • window.document.propertyName
• window.document.methodName
Parameters propertyName The defaultStatus, status, length, or name property of the
Document object.
165
BlackBerry Wireless Handheld Browser Content Developer Guide
Example In the following code fragment, the write() method takes several arguments,
including strings, a numeric, and a variable, and diplays the string "Hello world
testing 123":
var mystery = "world" msgWindow.document.write("Hello ",
mystery, " testing ", 123);
forward()
Goes forward one element in history.
Syntax window.forward()
Parameters none.
Example The following code adds a custom button to an HTML page that displays the next
item in the history list:
<P><INPUT TYPE="button" VALUE="< Back"
onClick="window.forward()">
frames
Specifies the frames that are contained by the current document. The handheld browser does not
support frames; instead, the browser displays a list of the frames in the frameset so that users can
open a selected frame as standalone page. This property is read-only.
Syntax window.frames[index]
Parameters index An integer that represents a child frame in the frameset, or the name of
the Frame object as specified by its name attribute.
Returns An array that contains the frame(s) associated with the document.
Example The following code fragment writes a list of the frames that are part of the current
document:
document.write("You have visited the following URLs during this
session:");
for (i=0; i < window.length; i++) {
document.write(window.frames[i]);
}
166
C: JavaScript language reference
history
Retrieves an array of recently accessed URLs, acquired from the History object. This property is
read-only.
Syntax • window.history[index]
• window.history.length
Parameters index An integer that represents a URL contained in the history list.
Properties length See "length" on page 141 for more information.
Returns An array that contains each element in the history list.
Example The following code fragment writes a list of the URLs that the user has visited
during the current session:
document.write("You have visited the following URLs during this
session:");
for (i=0; i < window.history.length; i++) {
document.write(window.history[i]);
}
home()
Returns to the page configured by the user as the browser homepage.
Syntax window.home()
Parameters none
Example The following code fragment displays the homepage, as it is configured in the
browser settings:
<INPUT TYPE="button" VALUE="Go to your homepage"
onClick="window.parent.home()">
location
Retrieves or sets the URL of the current window. This is a writable property.
Syntax • windowReference.location[.propertyName]
• windowReference.location.methodName(parameters)
Parameters windowReference The name of a window, or a synonym such as top or parent.
167
BlackBerry Wireless Handheld Browser Content Developer Guide
length
Returns the number of frames in a parent window. The handheld browser does not support frames;
instead, the browser displays a list of the frames in the frameset so that users can open a selected
frame as standalone page. This property is read-only.
Syntax windowReference.length
name
Returns the name of the window. This property is read-only.
Syntax windowReference.name
168
C: JavaScript language reference
open()
Opens a new browser window.
Syntax [windowName]=[window.]open(URL)
opener
A pointer back to the source window from the destination window. This is a writable property.
Syntax window.opener
Parameters none
Example The following code fragment closes the source window:
window.opener.close();
parent
A reference to the parent window. If no parent window exists, this property points to the current
active window. This is a writable property.
Syntax • parent.propertyName
• parent.methodName
Parameters propertyName The defaultStatus, status, length, or name property of the
Window object.
169
BlackBerry Wireless Handheld Browser Content Developer Guide
prompt()
Displays a prompt dialog box that prompts users for input.
Syntax window.prompt(message [,inputDefault])
self
A pointer to the current active window. This is a writable property.
Syntax • self.propertyName
• self.methodName
setInterval()
Sets a timer that enables you to evaluate an expression at regular intervals.
Syntax intervalID=window.setInterval(expression, msec)
Parameters intervalID An identifier that is used only to cancel the timeout evaluation with
clearInterval().
170
C: JavaScript language reference
setTimeout()
Sets a non-repeating timer that enables you to evaluate an expression after a specified amount of
time.
Syntax timeoutID=window.setTimeout(expression, msec)
Parameters timeoutID An identifier that is used only to cancel the timeout evaluation with
clearTimeout().
status
Defines the text in the status window. This is a writable property.
Syntax windowReference.status="message"
171
BlackBerry Wireless Handheld Browser Content Developer Guide
stop()
Stops the current download.
Syntax window.stop()
Parameters none
Example The following code fragment adds a button that enables users to stop the current
download.
<input type=button value="STOP" onClick="stop();">
top
Refers to the top window. Access to window.top only provides a URL, not the Window object itself.
Because the BlackBerry Browser is a single document interface, it attempts to maintain some idea
of window relationships. In many cases, window.top points to the current window. However, if
users arrived at the current window from a frameset, window.top points to the parent frameset.
This is a writable property.
Syntax • top.propertyName
• top.methodName
Parameters propertyName The defaultStatus, status, length, or name property of the
Window object.
window
Refers to the current window. This is a writable property.
Syntax • window.propertyName
• window.methodName
172
C: JavaScript language reference
173
BlackBerry Wireless Handheld Browser Content Developer Guide
174
D
WMLScript language reference
Using WMLScript
WMLScript libraries
Using WMLScript
The Wireless Markup Language (WML) is a broad, fairly easy-to-use language that permits content developers to
create reasonable content that can be viewed on all WAP browsers. Unfortunately, it lacks many aspects of a true
scripting language.
The solution is WMLScript, a wireless scripting language that can co-exist with WML decks. It is similar to
JavaScript, and is a modified subset of ECMAScript.
WMLScripts are independent files called as external references within WML decks. They are compiled into
bytecode at runtime on the server before they are sent to the WAP browser. Like C, C++, and Java, the language is
case sensitive and has a construct that is similar to C.
The format of a WMLScript function is as follows:
extern function NAME( [PARAMETERS(S)] )
{
// body of function
}
The extern keyword makes the function public to external files. Do not include extern on functions that are only
called from within the script.
Parameter passing is fairly lax where type is not specified in the parameter list. The caller of the function is
responsible for making sure that parameters passed to a function are in the expected format and sequence.
Note: The handheld browser currently does not support floating-point values.
See “Scripting Basics” on page 197 for information on WMLScript reserved words and supported statements,
operators, and expressions.
BlackBerry Wireless Handheld Browser Content Developer Guide
WMLScript libraries
The strength of WMLScript is largely contained with the function libraries. The libraries include functions to deal
with numeric values, dialog boxes and alerts, strings, relative and absolute URLs, and the browser.
The following WMLScript libraries are supported.
Lang
The Lang library contains 15 core library functions. For example, you can perform operations on integers, create
random numbers, create absolute values, stop code that is currently running, and determine support parameters.
abort()
Aborts the WMLScript and returns the passed string to the caller.
Syntax Lang.abort(ErrorMessage);
176
D: WMLScript language reference
Parameters ErrorMessage An error message that indicates the reason the script was aborted.
Returns No return value.
Example The following code fragment aborts the script and displays the given string:
Lang.abort("Script failure on line 123");
abs()
Returns the absolute value of the passed number.
Syntax Lang.abs(Number);
characterSet()
Returns a value that identifies the supported character set.
Visit http://www.iana.org/assignments/character-sets for a current list of character sets.
Syntax Lang.characterSet();
Parameters None.
Returns The numeric character-set identifier.
Example The following code fragment returns “3“, representing US-ASCII:
var charset = Lang.characterSet();
exit()
Exits the script and returns the passed message to the caller.
Syntax Lang.exit(Message);
177
BlackBerry Wireless Handheld Browser Content Developer Guide
isInt()
Tests whether the passed string can be converted into an integer value using parseInt().
Syntax Lang.isInt(StringValue);
max()
Determines the maximum value of two passed values in either integer or floating-point form.
Syntax Lang.max(Value1, Value2);
maxInt()
Returns the maximum value of an integer.
Syntax Lang.maxInt();
Parameters None.
Returns The maximum integer value.
Example The following code fragment returns “2147483647“:
var theMax = Lang.maxInt();
min()
Returns the minimum value of two passed values in either integer or floating-point form.
Syntax Lang.min(Value1, Value2);
178
D: WMLScript language reference
minInt()
Returns the minimum value of an integer.
Syntax Lang.minInt();
Parameters None.
Returns The minimum integer value.
Example The following code fragment returns “-2147483648“:
var theMin = Lang.maxInt();
parseInt()
Converts a string into an integer value.
Syntax Lang.parseInt(StringInt);
The following code fragment stops parsing on the first error that it encounters, and
therefore returns “987“:
var theInt2 = Lang.parseInt("9876Hi!!");
random()
Returns a random number between 0 and the passed value.
Syntax Lang.random(MaxRange);
179
BlackBerry Wireless Handheld Browser Content Developer Guide
seed()
Initializes the random number generator.
Syntax Lang.seed(SeedValue);
Dialogs
The Dialogs library contains three dialog box handlers that are used to display alert, confirmation, and prompt
dialog boxes. Users must respond to the displayed message or prompt for the script to continue running.
alert()
Displays a standard alert dialog box with an OK button.
Syntax Dialogs.alert(Message);
confirm()
Displays a standard confirmation dialog box with an OK and Cancel button.
Syntax Dialogs.confirm(Message, Button1, Button2);
180
D: WMLScript language reference
prompt()
Displays a prompt dialog box that prompts users for input.
Syntax Dialogs.prompt(Message, Default);
String
The String library contains 14 functions that can be used to manipulate strings.
The length of a string is determined by its total number of characters, including white space. Each character in the
string has an index position, where the first character is at position zero. A string can also be composed of a series
of elements that are delineated by separators. A separator can be any character.
The six types of white space are blank space, carriage return, form feed, line feed, horizontal tab, and vertical tab.
181
BlackBerry Wireless Handheld Browser Content Developer Guide
charAt()
Returns a single character that is located at the passed offset position within the passed string.
Syntax String.charAt(Buffer, Offset);
compare()
Compares strings where ranking is performed based on the ASCII value of each character within the
string.
Syntax String.compare(String1, String2);
182
D: WMLScript language reference
elementAt()
Locates a single element within the passed string buffer.
Syntax String.elementAt(Buffer, Element, Delimiter);
elements()
Counts how many times a delimiter occurs within a passed buffer to determine the number of
elements in the buffer.
Syntax String.elements(Buffer, Delimiter);
find()
Searches for the first occurrence of the passed substring within the passed buffer.
Syntax String.find(Buffer, SubString);
183
BlackBerry Wireless Handheld Browser Content Developer Guide
format()
Formats the passed numeric value as a string.
Syntax String.format(FormatString, Value);
Parameters FormatString Specifies the format of the string, which is configured as follows:
%[width][.precision]type
• width: Optional. When set, it specifies the minimum number
of characters that must be returned in the string.
• .precision: Optional. When set, it specifies the required
decimal precision that is set based on the setting of type.
• type: Required. The type argument can have one of the
following values:
• d: The source is treated as a positive or negative integer
value in the form of [-]n, where n is one or more decimal
digits.
If .precision is set, then the output value is padded on the
left side with up to the .precision number of zeroes.
• f: The source is treated as a positive or negative floating
point value in the form of [-]n.n, where n is one or more
decimal digits.
If .precision is set, then it is used to set the number of
digits after the decimal point, with at least one digit
appearing before the decimal point. The default precision
is 6. If 0 or a null value is specified after the decimal point,
then the decimal component is truncated.
• s: The source is treated as a string.
In this case, the width argument can be used to set the
minimum string size, and the .precision argument can
be used to set the maximum string size.
Value The value to be formatted as a string.
Returns A formatted string.
Example The following code fragment returns “BlackBerry rules!“:
var s5 = String.format("BlackBerry %s", "rules!");
The following code fragment returns “ 98.765%“ (with eight preceding blank
spaces):
var s6 = String.format("%10.3F%%", 98.7654);
184
D: WMLScript language reference
insertAt()
Creates a new string from the passed buffer that includes the passed field and field delimiter, which
is inserted at the passed field element number.
Syntax String.insertAt(Buffer, Field, Element, Delimiter);
isEmpty()
Determines whether the passed string is empty.
Syntax String.isEmpty(Buffer);
length()
Returns the length of a passed string.
Syntax String.length(Buffer);
185
BlackBerry Wireless Handheld Browser Content Developer Guide
removeAt()
Removes a field from the passed buffer at a specific element position.
Syntax String.removeAt(Buffer, Element, Delimiter);
squeeze()
Creates a string where all repeat white spaces in the passed string buffer are reduced to single
spaces.
Syntax String.squeeze(Buffer);
subString()
Returns a portion of the passed string.
Syntax String.subString(Buffer, Start, Size);
toString()
Returns a string representation of the passed parameter.
Syntax String.toString(Value);
186
D: WMLScript language reference
trim()
Eliminates any leading and trailing spaces from the passed string.
Syntax String.trim(Buffer);
URL
The URL library contains 14 functions that manipulate URLs. For example, you can extract the various portions of
the URL, escape and unescape special characters in the URL, determine the referring URL, and so on.
A URL is composed of some or all of the following components:
scheme://host:port/path;parameters$query#fragment.
escapeString()
Returns a string where special characters are changed into hexadecimal escape sequences.
187
BlackBerry Wireless Handheld Browser Content Developer Guide
getBase()
Returns the absolute URL (without the fragment) of the current WMLScript.
Syntax URL.getBase();
Parameters None.
Returns The absolute URL.
Example The following code fragment returns ”http://rim.com/script.wmls”:
var theURL = "http://rim.com/script.wmls#frag"
var absURL = URL.getBase();
getFragment()
Returns the fragment portion of the passed URL.
Syntax URL.getFragment(URL);
188
D: WMLScript language reference
getHost()
Returns the host that is specified within the passed URL.
Syntax URL.getHost(URL);
The following code fragment returns a null string, as the passed URL contains no
host component:
var theURL = "script.wmls";
var theHost = URL.getHost(theURL);
getParameters()
Returns the parameters within the last path segment of the passed URL.
Syntax URL.getParameters(URL);
The following code fragment returns a null string, as the passed URL contains no
parameters:
var theURL = "http://www.rim.com/script.wmls";
var parms = URL.getParameters(theURL);
getPath()
Returns the path that is specified within the passed URL.
Syntax URL.getPath(URL);
189
BlackBerry Wireless Handheld Browser Content Developer Guide
The following code fragment returns a null string, as the passed URL contains no
path:
theURL = "http://rim.com/";
thePath = URL.getPath(theURL);
getPort()
Returns the port that is specified within the passed URL.
Syntax URL.getPort(URL);
The following code fragment returns, a null string, as the passed URL contains no
port:
theURL = "http://www.rim.com";
thePort = URL.getPort(theURL);
getQuery()
Returns the query portion of the passed URL.
Syntax URL.Query(URL);
The following code fragment returns a null string, as the passed URL contains no
query component:
theQuery = URL.getQuery("http://www.rim.com");
getReferer()
Returns the smallest relative URL for the page, deck, or script that called the current script.
Syntax URL.getReferer();
190
D: WMLScript language reference
Parameters None.
Returns The referring URL.
Example The following code fragment might return the full URL or something relative such as
“mydeck.wml”. If there is no referrer, it returns a null string:
var whoCalled = URL.getReferer();
getScheme()
Returns the scheme within the passed URL.
Syntax URL.getScheme(URL);
The following code fragment returns a null string, as the passed URL contains no
scheme component:
var theURL = "www.rim.com/";
var theScheme = URL.getScheme(theURL);
isValid()
Validates the syntax of the passed URL.
Syntax URL.isValid(URL);
loadString()
Returns the content referred by the passed absolute URL and content type.
Syntax URL.loadString(URL, ContentType);
191
BlackBerry Wireless Handheld Browser Content Developer Guide
resolve()
Combines the passed base and relative URLs to return an absolute URL.
Syntax URL.resolve(baseURL, relURL);
Parameters baseURL The base portion of the passed URL (for example,
“http://www.rim.com/”).
relURL The relative path to a page, deck, or script (for example,
“index.shtml”).
Returns The resulting absolute URL.
Example The following code fragment returns “http://www.rim.com/index.shtml”:
var baseURL = "http://www.rim.com/";
var relURL = "index.shtml" );
var absURL = URL.resolve(baseURL, relURL);
unescapeString()
Returns a string where escaped characters have been restored to original form.
Syntax URL.unescapeString(escURL);
192
D: WMLScript language reference
Browser
The Browser library contains seven functions that can be used to access the information that is associated with
the WML cards. For example, you can return to a previously viewed card, go to a new card, refresh a card, and so
on.
getCurrentCard()
Returns the smallest relative URL of the current card being processed by the browser. If the current
card has a different base than the current script, this function returns the absolute URL of the card.
Syntax Browser.getCurrentCard();
Parameters None.
Returns A relative or absolute URL.
Example The following code fragment returns the current card being processed by the
browser:
var relURL = Browser.getCurrentCard();
getVar()
Returns the value of the passed variable name within the current browser context.
Syntax Browser.getVar(strName);
Parameters strName The name of the variable for which the value is to be returned.
Returns String value or invalid if not found.
Example The following code fragment returns the variable name (for example, “revers”):
var varVal = Browser.getVar("userid");
go()
Navigates the browser to the given URL.
Syntax Browser.go(navURL);
193
BlackBerry Wireless Handheld Browser Content Developer Guide
newContext()
Resets the browser context and clears all variables.
Syntax Browser.newContext();
Parameters None.
Returns An empty string.
Example The following code fragment resets the browser context:
var ret = Browser.newContext();
prev()
Navigates the browser to the previous card.
Syntax Browser.prev();
Parameters None.
Returns An empty string.
Example The following code fragment navigates the browser to the previous card:
var ret = Browser.prev();
refresh()
Refreshes the current page by pulling it from the server.
Syntax Browser.refresh();
Parameters None.
Returns An empty string.
Example The following code fragment refreshes the current page:
var ret = Browser.refresh();
setVar()
Sets the value of a variable.
Syntax Browser.setVar(varName, varValue);
194
D: WMLScript language reference
Parameters varName The name of the variable for which the value is to be set.
varValue The value to assign to varName.
Returns • Boolean true on success.
• Boolean false on failure.
Example The following code fragment sets the variable password to a value of “xyzzy”:
var isSet = Browser.setVar("password", "xyzzy");
195
BlackBerry Wireless Handheld Browser Content Developer Guide
196
E
Scripting Basics
Reserved words
Statements
Operators and expressions
Reserved words
The following are reserved words in WMLScript and/or JavaScript and cannot be used to name functions,
variables, methods, or objects.
• abstract • else • instanceof • struct
• access • equiv • int • super
• agent • enum • interface • switch
• Boolean • export • isvalid • synchronized
• break • extends • long • this
• byte • extern • meta • throw
• case • false • name • throws
• catch • final • native • transient
• char • finally • new • true
• class • float • null • try
• const • for • package • typeof
• continue • function • path • url
• debugger • goto • private • use
• default • header • protected • user
• delete • http • public • var
• div • if • return • void
• do • implements • short • volatile
• domain • import • sizeof • while
• double • in • static • with
BlackBerry Wireless Handheld Browser Content Developer Guide
Statements
The following WMLScript and/or JavaScript statements are supported by the handheld.
198
E: Scripting Basics
199
BlackBerry Wireless Handheld Browser Content Developer Guide
200
E: Scripting Basics
201
BlackBerry Wireless Handheld Browser Content Developer Guide
203
BlackBerry Wireless Handheld Browser Content Developer Guide
204
Index
Index
A troubleshooting push applications, 94
accept header, 34 bookmarks
access control, WML, 54 about, 24
actions, WML, 54, 57 browser
application pushes and downloads, supported, 16 acceptable content, 34, 35, 53
attributes browser detection, 34, 35
HTML, 39, 43, 44 creating effective images, 29
WML, 54, 56, 57, 58, 59 design guidelines, 27, 29, 46, 60
HTML and XHTML support, 97
B links, 27
BlackBerry menus, 55
model number, 34 push applications, 67
simulator, 47, 60, 65, 66 script support, 40, 53
BlackBerry Browser about, 9 supported content, 35
BlackBerry Browser configuration, 9 WML support, 129, 175
about, 11 browser push
options, 25 about, 67
BlackBerry Browser content
mobile media, 15 C
multi-part content, 17 cache, 24
supported markup languages, 15 cards, WML, 53, 55, 56
supported scripts, 16 central push server, 71
BlackBerry Browser features check boxes
bookmarks, 24 HTML, 43
cache, 24 WML, 54
cookies, 23 code samples See examples
history, 23 configuration, 10
supported, 13 configuration icons, 10
BlackBerry Browser images connection
conversion, 15, 17 HTTP, 71
supported, 15 SSL, 11
BlackBerry Browser interface content
links, 22 conversion, 71
menus, 21 delivering content based on, 34
screen, 21 markup languages, 28
soft keys, 22 scripts, 53
BlackBerry Browser protocols, 11 server, 29, 34, 54
BlackBerry Browser push supported types, 35, 54
downloads and, 16 testing, 47, 60
BlackBerry Browser service books, 10 cookies, 23
BlackBerry Enterprise Server creating
205
BlackBerry Wireless Handheld Content Developer Guide
bitmaps, 29 HTML, 39
check boxes in HTML, 43 forms
effective images, 29 HTML, 42
forms in HTML, 42 WML, 56
links in HTML, 42
option lists in WML, 57 G
phone links, 44 gateway
WML cards, 55 WAP, 29
D H
decks, WML, 27, 54, 55, 56 handheld
depth, color, 27 model number, 36
do elements, WML, 54 simulator, 65
software versions, 34
E headers
elements accept, 34, 35
access, WML, 54 history, browser, 23
card, WML, 59 home page, 27, 55
disabling, WML, 59 HTML
do, WML, 54 alt attribute, 44
form, HTML, 42 check boxes, 43
form, WML, 56 effective links, 42
go, WML, 59 fonts, 39
horizontal rule, HTML, 42 forms, 40, 42
noop, WML, 59, 122 images, 44
sequence, WML, 56 navigation bar, 42
syntax, WML, 53 option lists, 43
timer, WML, 58 page outline, designing, 42
email address page redirection, 41
PIN mapping, 94 phone links, 44
email links, HTML, 44 script support, 40
events supported tags, 97
WML, 54, 57, 58 HTTP
examples headers, 34, 35, 72
browser detection script, 35 request, 34, 71
BrowserChannelPush.java, 78, 87
handheld color detection, 37 I
index.pl, 35 icons, 10, 66
login.html, 41, 47 images
login.wml, 60 adding in WML, 57
alignment, 57
F color, 19
fonts conversion, 15, 17
206
Index
207
BlackBerry Wireless Handheld Content Developer Guide
HTML, 43 simulator
WML, 54, 57 icons, 65, 66
installing, 65
P keyboard, 66
phone links, HTML, 44 Mobile Data Service, 65
PIN starting, 65
email mapping, 94 trackwheel, 66
port, default, 71 using, 47, 60, 65, 66
push applications size
about, 67 content limitation, 29
central push server, 71 limitations, 27, 29
Mobile Data Service, 71 soft keys, 22
process, 71 soft keys, WML, 54, 123
troubleshooting, 94 starting simulator, 65
types, 67 supported
content types, 54
writing, 71
image types, 35
syntax
R
WML, 53
radio buttons
HTML, 43 T
WML, 54
templates, WML, 55
testing
S content, 47, 60
sample code using simulator, 47, 60, 65
color handheld detection, 37 WML pages, 46, 60
HTML login page, 41, 47 timeline events, WML, 58
HTML redirection, 41 trackwheel
Perl script, 56 implications for design, 27
WML login page, 60 using in simulator, 66
scaling images, 29
screen W
size, 27
WAP Browser about, 9
scripts WAP Browser configuration, 9
browser detection, 34, 35
about, 10
browser support for, 40
options, 25
CGI, 42
WAP Browser content
WML, 53 mobile media, 15
scrolling, trackwheel, 54, 66 multi-part content, 17
select items, WML, 54 supported markup languages, 15
server
content, 29, 34, 54 supported scripts, 16
WAP Browser features
web application, 29, 34, 54
bookmarks, 24
service books
cache, 24
configuration, 10
208
Index
209
BlackBerry Wireless Handheld Content Developer Guide
210
©2005 Plazmic, Inc.
Published in Canada.