Account Options

Help

Developers » Web Developers » Code

Sample Code

Using BrowserPlus™ is simpler than you might think. We've created some samples to demonstrate how simple. If BrowserPlus is installed, you'll be also be able to run the samples on this page.

 1

Introduction

Check for and initialize BrowserPlus.

 2

Detecting BrowserPlus

How to detect if BrowserPlus is installed.

 3

Using Services

How to specify in your webpage what BrowserPlus services you require.

 4

Errors & Return Values

How results are asynchronously returned.

 5

Drag and Drop

Hooking up a drop target in a webpage.

 6

Accessing Files

Previewing and getting contents of files that users select.

 7

Uploading Modified Images

A demo showing how to use ImageAlter and Upload in a chain to upload images altered on the client.

 8

File Zipper

A demo showing how to use Zipper and Upload in a chain to compress all files into one *.zip file before uploading.

 9

All About Uploading

A demonstration of the various features of the uploader service.

10

Image Twiddler

A complete web application that demonstrates client side image manipulation, tying together the concepts thus far.

11

Publish Subscribe

Shows how two different browser windows (even from different browsers) can send messages back and forth.

Errors & Return Values

Description

This sample demonstrates the conventions used when data is returned from a BrowserPlus service. The PStore service is the tool we use to explore return values.

In the previous sample we covered the asynchronous nature of service invocation, in this sample we'll go a little further into the structure of information that's returned. Here we can see that BrowserPlus.PStore.get() is invoked with two arguments: the first is an object holding named arguments, the second is a function which will be invoked when the call completes. This function accepts a single argument which holds the status of the call and returned data. This two argument calling convention is common to all functions on all services.

What we haven't covered yet is how information and errors are returned inside the argument to the callback function. Result callbacks will always be invoked with an object. That object will always have a success property. When success is true, the value property will contain the return value of the function. Here is a JSON depiction of a return object resulting from a successful service invocation:

When there are errors in the invocation, the success property holds boolean false, and an error member is present which includes a textual error code. Optionally, a verboseError property may also be present which holds a developer readable english string describing what went wrong:

With this last bit of foundation laid, we're ready to jump in and start building web applications on BrowserPlus. Next we'll look at a key BrowserPlus feature, which allows javascript to get at drag and drop from the desktop...