Detecting BrowserPlus
This code sample demonstrates how you can detect whether BrowserPlus is installed.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <html>
<head><title>What If BrowserPlus Isn't installed?</title></head>
<body>
Let's see if BrowserPlus is installed...
<script src="http://bp.yahooapis.com/2.9.9/browserplus-min.js"></script>
<script class="javascript">
BrowserPlus.init(function(r) {
function bplusInitialized() {
// this function will be called when BrowserPlus is ready,
// either after the user goes and installs it, or immediately if
// BrowserPlus was already installed.
// so... require some services!
}
if (r.success) {
// BrowserPlus is installed and ready to go!
alert("Yahoo! BrowserPlus installed, v" + BrowserPlus.getPlatformInfo().version);
bplusInitialized();
} else if (r.error == "bp.notInstalled") {
// BrowserPlus isn't installed, but the client browser/operating system
// is supported! we can render a link to let our users know that
// more features are available if they install the thing.
BrowserPlus.initWhenAvailable({}, bplusInitialized);
alert("Get BrowserPlus! You can do it!");
} else if (r.error == "bp.unsupportedClient") {
// Uh oh, they're running a browser we don't yet support. We should
// probably disable features that require browserplus, and rendering
// an installation link for BrowserPlus is useless.
} else {
// yikes! Unexpected error!
throw(r.error + ": " + r.verboseError);
}
});
</script>
</body>
</html> |
| Run Example | |
Inline comments describe the possible cases when you call BrowserPlus.init():
- r.success === true
- BrowserPlus is installed and ready to use
- r.error === 'bp.notInstalled'
- BrowserPlus is not installed and client platform is supported
- r.error === 'bp.unsupportedClient'
- BrowserPlus is not installed and client platform is NOT supported
- otherwise
- BrowserPlus encountered an error during initialization
The last two cases should be considered failure cases, and as a developer you should disable BrowserPlus functionality. In
the second case you can render a link pointing to http://browserplus.yahoo.com/install, and describe to your user what
features will become available to them if they install BrowserPlus. Further, if you would like to automatically detect when
BrowserPlus is installed without a page reload you can use the BrowserPlus.initWhenAvailable() platform function which will
set up a poller and once init() completes successfully, will invoke the callback you provide.
Using this handful of tools it should be possible to craft the precise experience you're looking for.

