views:

322

answers:

2

I have a typical Ext Js style window with a left navigation, header and central region to display stuff.

The left navigation has a bunch of menu items that when clicked on load something via the Panel.Load() method from a specified url into the central panel.

My problem is that in IE if i click many menu items too fast i get various javascript errors, I believe dom elements are trying to be accessed that no longer exists as the updater is in the process updating the html.

Has anyone come across this or is there anyway to stop javascript executing once a new load request has started.

I have tried using this:

    if(Ext.isIE) {
        window.document.execCommand('Stop');
    }
    else {
        window.stop();
    }

Thanks in advance!

A: 

Simple solution comes to mind: you could create a global variable to indicate that loading is in progress, and check it immediately after menu item is clicked. And only continue execution if loading is not already in progress.

Tommi
Yes this is an option but I dont want to halt user activity. One of the pages could take a long time to load sday 5 secs plus. If they click this by accident ideally i would just like the javascript to be cancelled and the new event triggered straight away otherwise the system could become annoying to use and sluggish for the user
Jonnio
+2  A: 

A common solution to handling overly-fast clicking is to buffer the click handling code that loads your panels so that it only runs if another click does not occur within a specified time period. Something like:

item.on('click', function(){ ... }, this, {buffer:50});
bmoeskau
Ok might work for a single button and if the page loaded in less than 50 milliseconds. But there are many menu items. If the user click A then B then C and error will occur. Also C could take 5 seconds to load being a very heavy duty page so I was really looking for a way that would cancel the current load rather stopping the user from triggering a new event.
Jonnio
I'm not sure that you are clear on how buffering works. The idea is that in your example, if A and B are clicked more quickly than the buffer threshold then they will never be loaded, thus you should not get an error. Granted if you have something that takes 5 seconds and the user clicks on something else after 4 seconds, you will have to handle that separately. But I still think buffering might help you with the "fast click" scenario (and is usually a good approach in general when multiple quick clicks can cause problems).
bmoeskau
OK, your right, I was not clear. This sounds like it could help but I am unsure as to how i could apply this to accordian item clicks.
Jonnio