2

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
  • Not to intentionally toot the eval is eval horn here, but maybe there's another way to achieve what you're trying to do without using eval?
    – Andy E
    Apr 27, 2010 at 11:06
  • 2
    No-one's going to argue with you that eval is eval...
    – Tim Down
    Apr 27, 2010 at 11:13

1 Answer 1

3

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!");
    }
}
5
  • 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
    Apr 27, 2010 at 11:08
  • 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
    Apr 27, 2010 at 11:29
  • When I look at the src I see javascript:false in IE (data:... for Firefox but not for IE), I'll keep digging.
    – Motti
    Apr 27, 2010 at 12:21
  • If you come up with anything, please post again: I'd like to know the answer to this too.
    – Tim Down
    Apr 27, 2010 at 15:48
  • 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
    May 10, 2010 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.