Adobe AIR Open New URL with Sandbox Bridge


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. //This code is placed in the root document header
  2. //This function is written to run from the sandbox. It opens a url in an external browser
  3. function openExternalURL(href) {
  4. var request = new air.URLRequest(href);
  5. try {
  6. air.navigateToURL(request);
  7. }
  8. catch (e) {
  9. // handle error here
  10. }
  11. }
  12.  
  13. //Create an object that will be used to expose AIR functionality to the browser sandbox
  14. var Exposed = new Object();
  15.  
  16. //Exposed can now be read from the sandbox, so can the above function. The open url
  17. //function is added as a method of the exposed object.
  18. Exposed.openExternalURL = openExternalURL;
  19.  
  20. function doLoad() {
  21. //Place the Exposed object on the parentSandboxBridge property of the ui frame's window object.
  22. var frame = document.getElementById('UI').contentWindow.parentSandboxBridge = Exposed;
  23. }
  24. //doLoad is placed inline on the body tag.
  25.  
  26. //Now to run the external function from inside the sandbox use. The function expects
  27. //an argument that contains a URL.
  28. parentSandboxBridge.openExternalURL(href);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.