为什么这个window对象没有eval函数?

发布于 2024-08-30 06:07:16 字数 770 浏览 0 评论 0原文

我在 YUI rich edit demo 在 IE 上。当查看用作浏览器的内容可编辑框架的 window 对象时,我发现 eval 函数未定义(通过运行以下命令)。

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

这种情况只发生在 IE 上(我在 IE6 和 IE8 上检查过),在 Firefox 或 Chrome 上不会发生。

所有其他 window 函数和属性似乎都在顺序,现在我意识到 eval 并不是真正在 window 上定义的,而是在全局对象上定义的,但我的理解是在浏览器中 >window 全局对象(而且eval确实出现在所有其他窗口上,为什么不在这个窗口上呢?)。

有谁知道这是否是 IE 中的已知错误/限制以及如何在此框架的全局对象的上下文中进行 eval ? (我需要副作用可用于此框架内运行的任何内容)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有你我更好 2024-09-06 06:07:16

我不久前发现,您可以首先使用 execScript 使 eval 神奇地出现在 IE 中的 iframe 窗口对象中:

function evalIframe(iframeWin, command) {
    if (!iframeWin.eval && iframeWin.execScript) {
        iframeWin.execScript("null");
    }
    if (iframeWin.eval) {
        iframeWin.eval(command);
    } else {
        alert("No eval!");
    }
}

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!");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文