/ Published in: JavaScript
Adobe Air has a few security settings that stops you executing certain AIR methods when inside the sandbox. The code below bridges between the root document and the security sandbox, allowing you to open a URL in AIR in a default browser.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//This code is placed in the root document header //This function is written to run from the sandbox. It opens a url in an external browser function openExternalURL(href) { var request = new air.URLRequest(href); try { air.navigateToURL(request); } catch (e) { // handle error here } } //Create an object that will be used to expose AIR functionality to the browser sandbox var Exposed = new Object(); //Exposed can now be read from the sandbox, so can the above function. The open url //function is added as a method of the exposed object. Exposed.openExternalURL = openExternalURL; function doLoad() { //Place the Exposed object on the parentSandboxBridge property of the ui frame's window object. var frame = document.getElementById('UI').contentWindow.parentSandboxBridge = Exposed; } //doLoad is placed inline on the body tag. //Now to run the external function from inside the sandbox use. The function expects //an argument that contains a URL. parentSandboxBridge.openExternalURL(href);