We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 01/02/08


Tagged

url open AIR bridge adobe


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

lukaszkorecki


Adobe AIR Open New URL with Sandbox Bridge


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.

  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 

You need to login to post a comment.