2 Replies Latest reply on Mar 6, 2009 11:54 PM by hkor

    Air - JavaScript DOM problems

      Dear Air-friends,

      Have a look at this short html:

      <script type="text/javascript" src="AIRAliases.js"></script>
      var i = 0;
      var click = function() {
      var a = document.createElement("a");
      a.innerHTML = "click me " + i++;
      a.setAttribute("href", "#");
      a.setAttribute("onclick", "click()");

      document.getElementById("body").replaceChild(a, document.getElementsByTagName("a")[0]);
      <body id="body" onload="click()">
      <a />

      when I run this using adl something strange happens:
      - I get a "click 0", after I click a "click 1" and .... that's it! no continuous "click 2", etc.

      I isolated this problem to this example, but actally I need it for context menus in my air application.

      Can someone help? I'm out of ideas.


      Harrold Korte
        • 1. Re: Air - JavaScript DOM problems
          Joe ... Ward Level 4
          a.addEventListener("click", click);
          to add the event listener. Setting an attibute is essentially evaluating a string as code -- which isn't allowed after the load event fires. The first time the code is run before the load event, so it works, but not afterwards.
          • 2. Re: Air - JavaScript DOM problems
            hkor Level 1
            Hi Joe,

            First of all, thanks for your quick reply!

            Maybe I isolated the problem a bit too much. In fact, I'm creating context menus using xslt.
            Each time, a new context menu is put under a node called <div id="wrap-menu"> containing
            a <ul> of <a>s. It is in these subsequent refreshing of the context-menu (produced by xslt)
            where I observed this behaviour (first time ok, second time nop). Should I alter each <a> in the produced context-menu with addEventListener afterwards?

            I have the feeling that in that case I could didge xslt as well. Unfortunatly, I'm a big xslt fan to create
            html output (instead of all these program lines of unpacking and DOM manipulation). I'm porting an
            application from JS/PHP to Air because of the file system access which is exactly what I was looking for.

            Thanks again,

            Harrold Korte