| Home Beta programs |
Welcome to Mobipocket Developer Center |

Mobipocket Javascript support (Reader Pro 4.6 and higher)Design goalsThis implementation of a subset of Javascript is primarily designed to enable:
Overview & RestrictionsOnly a limited subset of Javascript is supported in Mobipocket Reader Pro 4.5 :
Supported Operators
|
| Supported functions | Description |
Math.abs(number)
|
Returns the absolute value of a number. |
Math.acos(number)
|
Returns the arccosine of a number. |
Math.asin(number)
|
Returns the arcsine of a number. |
Math.atan(number)
|
Returns the arctangent of a number. |
Math.atan2(y, x) |
Returns the angle (in radians) from the X axis to a point (y,x). |
Math.ceil(number)
|
Returns the smallest integer greater than or equal to its numeric argument. |
Math.cos(number)
|
Returns the cosine of a number. |
Math.exp(number)
|
Returns e (the base of natural logarithms) raised to a power. |
Math.floor(number)
|
Returns the greatest integer less than or equal to its numeric argument. |
Math.log(number)
|
Returns the natural logarithm of a number. |
Math.max([number1[,
number2[. . . [, numberN]]]]) |
Returns the greater of zero or more supplied numeric expressions. |
Math.min([number1[,
number2[. . . [,numberN]]]]) |
Returns the lesser of zero or more supplied numeric expressions. |
Math.pow(base, exponent)
|
Returns the value of a base expression taken to a specified power. |
Math.random( ) |
Returns a pseudorandom number between 0 and 1. |
Math.round(number)
|
Returns a supplied numeric expression rounded to the nearest integer. |
Math.sin(number)
|
Returns the sine of a number. |
Math.sqrt(number)
|
Returns the square root of a number. |
Math.tan(number)
|
Returns the tangent of a number. |
As there is no possible debugging and no error report in the Mobipocket Reader, it is recommended to test the javascript code in Microsoft Internet Explorer and verify that the Javascript syntax is correct before testing in the Mobipocket Reader. The syntax supported by the Mobipocket Reader is strictly javascript compliant.
| Tag Name | Attribute Name | Description |
| FORM | An enclosing form tag is mandatory to display the form input items | |
| name="myformname" | mandatory | |
| action="myurl" | optional | |
| method="post" or "get" | optional, default is "get" | |
| enctype="application/x-www-form-urlencoded" or "xml" | optional. default is "application/x-www-form-urlencoded" the "xml" value sends the form data as an xml string (Mobipocket specific). Works only if method="post" is specified. |
|
| INPUT | ||
| name="mytagname" | mandatory | |
| type="text", "button", "checkbox", "submit", "reset", "hidden" | default is "text". radio, img, file types are not supported. | |
| value="myvalue" | ||
| checked | The presence of this attribute is used to initialize checkboxes to their checked state | |
| size="my numeric value" | Used to set the visible size of text fields to a given number of average character widths | |
| onclick="my javascript code" | supported only when type="button" or type="submit" | |
| SELECT | Used for a combo box | |
| name="mytagname" | mandatory | |
| onchange="my javascript code" | optional | |
| OPTION | a combo box item | |
| value="my value" | optional | |
Remarks :
| Property | Applies to | Comment |
| value | <input type="text"> | Read / Write property |
| checked | <input type="checkbox"> | Read / Write property. Can be set to true or false |
| selectedIndex | <select> | Read / Write property. Can be set to a numeric value. It is zero based (first item is 0) |
Form widget objects can be accessed and their properties can be get or set.
To reference a widget :
Example : form.mywidgetname
<form name="frm1">
<input type="text" name="editbox1" value="123" />
<input type="button" onclick="alert(form.editbox1.value)" value="Test1"
/>
<input type="button" onclick="alert(document.frm1.editbox1.value)"
value="Test1" />
</form>
Input data forms can be submitted to a Web server at a given URL during the next synchronization of the PDA with the PC. It works like a standard form submit on a web page, expect that the data are not sent directly, but stored in an internal database on the PDA. At next sync, these data are sent to the desktop PC and then the HTTP request containing the form datas is submitted by the Mobipocket Web Companion.
Use the action="myurl" attribute in the <FORM> tag, along with a <input type=submit> tag to post form data.
Warning : clicking multiple times on the submit button of an HTML form will submit the data multiple times (just like in any Web Browser).
Example :
| <form action="www.mobipocket.com/getdata.asp"
method="get"> Enter your name : <input type="text" name="username"> <br> <input type="submit"> </form> |
Some custom optional mobipocket hidden attributes can be added in the form
tag to enable further customization of form posting.
| Mobipocket Custom Hidden Attributes | Description |
| <input type="hidden" name="mbpwc_inbrowser" value="yes"> | Indicates that the HTTP request sent by the WebCompanion should
be played in a visible WebBrowser and not in background. This enables a
response page to be displayed on the user's PC. The default is "no". This is optional. Note that if value is "yes", the method attribute in the Form is ignored and GET method is used. |
| <input type="hidden" name="mbpwc_title" value="Some Caption"> | Indicates to the Web Companion a user friendly caption to
identify the Web site where data is posted in case an error message needs
to be displayed. This is optional. |
| <input type="hidden" name="mbpwc_errormsg" value="Some Caption"> | Specify a custom error message to be displayed by the Web
Companion if the data cannot be posted on the user's PC. This is optional. |
| <input type="hidden" name="mbprdr_pid" value="%%PID%%"> | Sends the PDA PID in the field mbprdr_pid hidden attribute. Works only if the action url points to www.mobipocket.com . |
| <input type="hidden" name="mbprdr_silent" value="yes"> | if value="yes" Does not display any alert message after form submission at all. Default is value="no". (Requires Reader 4.7 build 409 or higher) |
© Copyright 2000-2007 Mobipocket.com