views:

65

answers:

1

I ran into an interesting (?) problem in the YUI rich edit demo on IE. When looking at the window object for the content editable frame used as the browser I see that the eval function is undefined (by running the following).

javascript:alert(document.getElementById("editor_editor").contentWindow.eval)

This only happens on IE (I checked on IE6 and IE8), and it doesn't happen on Firefox or Chrome.

All the other window functions and properties seem to be in order, now I realise that eval is not really defined on the window but on the global object but my understanding was that in browsers the window is the global object (also eval does appear on all other windows so why not on this one?).

Does anyone know if this is a know bug/limitation in IE and how I can get to eval in the context of the global object of this frame? (I need the side effects to be available to anything running from within this frame).

+2  A: 

I discovered a while back that you can make eval magically appear in an iframe's window object in IE by using execScript first:

function evalIframe(iframeWin, command) {
    if (!iframeWin.eval && iframeWin.execScript) {
        iframeWin.execScript("null");
    }
    if (iframeWin.eval) {
        iframeWin.eval(command);
    } else {
        alert("No eval!");
    }
}
Tim Down
Thanks Tim, I tried it and got "Access is denied": `javascript:try { document.getElementById("editor_editor").contentWindow.execScript('null') } catch (ex) { alert(ex.message) }`
Motti
Oh. This has worked for me on iframes I've created dynamically. I'd expect `eval` not to work either then. All I can think of is that it could be because YUI editor is using a `data:` URL as the `src` for the iframe, which may be causing IE to prevent access because the iframe URL is using a different protocol to the main document's URL.
Tim Down
When I look at the `src` I see `javascript:false` in IE (`data:...` for Firefox but not for IE), I'll keep digging.
Motti
If you come up with anything, please post again: I'd like to know the answer to this too.
Tim Down
@Tim, no progress on this (other things took priority) however I did discover that (in IE8) this doesn't happen if the debugger is attached...
Motti