Search code examples
javascriptinternet-explorerpropertieswindow

Deleting a window property in IE


I can't find any information on this issue; why doesn't the following code work in IE?

window.x = 45;
delete window.x;
// or delete window['x'];

IE reports an "object doesn't support this action" error. Does it have anything to do with that iterating over window properties in IE issue?


Solution

  • I would do it this way:

        window[x] = undefined;
        try{
            delete window[x];
        }catch(e){}