1 Reply Latest reply on Oct 25, 2010 8:39 AM by <svg onload=alert('1')>

    Link in Adobe AIR JavaScript app is incorrectly opening the app in the default browser

    denisahearn

      I have a couple of links in my Adobe AIR JavaScript app that are part of the app's UI, which when clicked are causing the app to be loaded into a new tab in my default browser.

       

      This is only happening with two links (Save and Cancel on a form), and not all links in my UI.  The two links that are having the issue are defined in an external HTML file that I load a runtime and connect to the DOM.  The links that are defined in the main HTML file that is loaded when the app starts up do not have this problem.

       

      Here is how I am loading the template and plugging it into the DOM

       

      var win = document.createElement("div");

      var f = air.File.applicationDirectory.resolvePath("lib/partials/edit_form.html");
      var fs = new air.FileStream();
      fs.open(f, air.FileMode.READ);
      var content = fs.readUTFBytes(fs.bytesAvailable);
      fs.close();
      var template = new Template(content);

      win.innerHTML = template.evaluate(data);

      document.body.insertBefore(win, document.body.firstChild);

       

      The links themselves are coded like this:

       

      <a href="#" id="save_button" onclick="return false;"></a>

      <a href="#" id="cancel_button" onclick="return false;"></a>

       

      I am using the Prototype JS library to observe the 'click' event for each of these links like so:

       

      $('save_button').observe('click', onSave);

      $('save_button').observe('click', onCancel);

       

      This app shows content created by users, which can contain links to external web sites.  To get the external links to open in the browser (as opposed to inside my Adobe AIR window), I am doing the following in a script tag in the head of my main HTML file:

       

      window.htmlLoader.navigateInSystemBrowser = true

       

      I've found that if I set window.htmlLoader.navigateInSystemBrowser = false, then the issue with the Save and Cancel links described above goes away.  However, I need to have window.htmlLoader.navigateInSystemBrowser = true so that external links in the user content open up in the browser, not in Adobe AIR.

       

      Another piece of evidence is that the Save and Cancel links only incorrectly open a browser the first time you click on them after launching the app.  Subsequent clicks work fine and do not have the issue.

       

      Any ideas on why the links that are plugged into the DOM after app start up have this issue, and only the first time you click on them?