Loading ...
Sorry, an error occurred while loading the content.

IE and "AddImportListener" issue. FF works fine.

Expand Messages
  • Sam Amos
    Hi Mike, I m hoping you can shed some light on the issue I m having with IE and AddImportListener. Here is what I m trying to do. //BEGIN index.js var pages =
    Message 1 of 2 , Jun 20, 2008
    • 0 Attachment
      Hi Mike,

      I'm hoping you can shed some light on the issue I'm having with IE and
      AddImportListener.

      Here is what I'm trying to do.

      //BEGIN index.js
      var pages = {};
      var currentPage;

      function initialize()
      {
      load_page('Home');
      }

      function load_page(page)
      {
      currentPage = page;
      Namespace(page);
      Ajile.AddImportListener(page, page_init);
      Load('../../js/page/'+page+'.js');
      }

      function page_init()
      {
      pages[currentPage].init();
      }
      //END index.js

      //BEGIN Home.js
      Namespace("Home");

      var Home = {
      init: function()
      {
      alert('init Home');
      }
      }
      pages['Home'] = Home;
      //END Home.js

      //BEGIN html
      <html>
      <head>
      <title></title>
      <script type="text/javascript"
      src="http://my.domain/js/com.iskitz.ajile.js?mvcoff"></script>
      </head>
      <body onLoad="initialize();">
      <a href="#" onClick="pages[currentPage].init();">Click Me</a> </body>
      </html>
      //END html

      This works fine in FF but IE throws a Runtime Error
      "pages[...]" is null or not an object. However when I click the "Click
      Me" link in IE the method init() is called just fine.

      So it seems that IE is firing the ImportListener "page_init" before it
      has actually loaded "Home.js", because after the page has finished
      loading the object defined in "Home.js" is available to use.

      I'm hoping you can tell me if I'm doing something wrong here or if
      this is an IE issue with AJILE.

      Thank you for your help

      Sam
    • mikeizworkin
      Hi Sam, The problem seems to be inconsistent. I wasn t able to reproduce it in any version of IE, but did see it temporarily in Firefox 3. I believe you can
      Message 2 of 2 , Jun 20, 2008
      • 0 Attachment
        Hi Sam,
        The problem seems to be inconsistent. I wasn't able to reproduce it in
        any version of IE, but did see it temporarily in Firefox 3.

        I believe you can resolve it by removing the Namespace(page) statement
        from the load_page() function in your index.js file.

        This is most-likely causing the problem because when load_page("Home")
        is called:

        1. Namespace(page) immediately creates a "Home" object for the Home
        namespace.

        2. Ajile.AddImportListener(page,...) immediately checks for the
        existence of the Home object before adding a listener.

        3. Ajile.AddImportListener(page,...) finds the Home object created by
        Namespace(page) and so immediately executes your page_init() function.

        4. page_init() accesses the pages array and generates the error
        because load_page(page) hasn't as yet gotten to load Home.js.


        Basically, you correctly used Namespace("Home") in your Home.js file,
        but incorrectly used it in the load_page(page) function in your
        index.js. You should use Namespace(...) within script files to define
        their namespace, rather than outside of the script file prior to
        loading it, especially if you plane to listen for the script's
        availability.

        Hope that helps to clarify.

        Good luck!

        -Mike

        --- In ajile@yahoogroups.com, "Sam Amos" <o0shadow0o@...> wrote:
        >
        > Hi Mike,
        >
        > I'm hoping you can shed some light on the issue I'm having with IE and
        > AddImportListener.
        >
        > Here is what I'm trying to do.
        >
        > //BEGIN index.js
        > var pages = {};
        > var currentPage;
        >
        > function initialize()
        > {
        > load_page('Home');
        > }
        >
        > function load_page(page)
        > {
        > currentPage = page;
        > Namespace(page);
        > Ajile.AddImportListener(page, page_init);
        > Load('../../js/page/'+page+'.js');
        > }
        >
        > function page_init()
        > {
        > pages[currentPage].init();
        > }
        > //END index.js
        >
        > //BEGIN Home.js
        > Namespace("Home");
        >
        > var Home = {
        > init: function()
        > {
        > alert('init Home');
        > }
        > }
        > pages['Home'] = Home;
        > //END Home.js
        >
        > //BEGIN html
        > <html>
        > <head>
        > <title></title>
        > <script type="text/javascript"
        > src="http://my.domain/js/com.iskitz.ajile.js?mvcoff"></script>
        > </head>
        > <body onLoad="initialize();">
        > <a href="#" onClick="pages[currentPage].init();">Click Me</a>
        </body>
        > </html>
        > //END html
        >
        > This works fine in FF but IE throws a Runtime Error
        > "pages[...]" is null or not an object. However when I click the "Click
        > Me" link in IE the method init() is called just fine.
        >
        > So it seems that IE is firing the ImportListener "page_init" before it
        > has actually loaded "Home.js", because after the page has finished
        > loading the object defined in "Home.js" is available to use.
        >
        > I'm hoping you can tell me if I'm doing something wrong here or if
        > this is an IE issue with AJILE.
        >
        > Thank you for your help
        >
        > Sam
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.