Safari 5.1 和 Javascript recognize() 函数的错误

发布于 2024-12-05 09:07:01 字数 1330 浏览 0 评论 0原文

下面更新

我想我刚刚在 OS X Lion 上的 Safari 5.1 中发现了一个非常奇怪的错误。我无法确定此错误是否存在于早期版本的 Safari 中,但我有点怀疑不存在(考虑到我的网站中引用此问题的部分曾经在 Lion 之前的 Safari 中运行)。我在 Chrome、Firefox 6、IE7 或 IE9 中没有看到该错误。我还能够确认该错误不会发生在 Windows 7 上的 Safari 5.0.2 中,这可能意味着这是 Safari 5.1 中的新功能。

所以这里有一个错误:如果 javascript recognize() 函数位于另一个函数内部,那么该函数中调用的任何内容在确认()之前都不会执行,直到“OK”或“单击“取消”按钮。对我来说,这确实是一个巨大且非常奇怪的错误。这是我的示例代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

function myexit () {
    console.log(0);

    if ( confirm('Are you sure?') ) {
        window.close();
    }
}
</script>
</head>
<body>
<a href="#" onclick="myexit();">close window</a>
</body>
</html>

在我提到的所有其他浏览器中,0 出现在控制台中,同时出现模式确认框。在 Safari 中,0 仅在单击“确定”或“取消”后出现。

另外,如果我将confirm()函数放在子函数中,如下所示:

function confirmwrapper() {

    if ( confirm('Are you sure?') ) {
        console.log(1);
    }
}

function myexit () {
    console.log(0);
    confirmwrapper();
}

...它仍然会中断。

我在这里缺少一些基本的东西吗?恕我直言,像“只使用 JQuery/Mootools/其他一些很酷的 JS 库”这样的答案可能对我没有多大帮助,因为这段代码是遗留系统的一部分,我现在无法完全分解它,就像我一样想要。

更新:我刚刚测试了一个简单的 AJAX 请求(Mootools Request(),对于那些记分的人,尽管我认为这并不重要),并且我能够确认该请求被执行直到确认对话框关闭——通过“确定”或“取消”。这一定是一个错误。坚果。

提前致谢

UPDATE BELOW

I think I've just found a really weird bug in Safari 5.1, on OS X Lion. I can't confirm for sure whether this bug existed on earlier versions of Safari, but I sort of suspect not (given the fact that the part of my site that references this issue used to work in pre-Lion Safari). I don't see the bug in Chrome, Firefox 6, IE7 or IE9. I've also been able to confirm that the bug does not happen in Safari 5.0.2 on Windows 7, which likely means this is new to Safari 5.1.

So here's the bug: it would appear that if the javascript confirm() function is inside of another function, then anything within that function called before confirm() is not executed until either the "OK" or "Cancel" button is clicked. That sure seems like a huge, and really weird, bug to me. Here's my sample code:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

function myexit () {
    console.log(0);

    if ( confirm('Are you sure?') ) {
        window.close();
    }
}
</script>
</head>
<body>
<a href="#" onclick="myexit();">close window</a>
</body>
</html>

In all the other browsers I mention, the 0 appears in the console at the same time the modal confirm box appears. In Safari, the 0 appears only after clicking either "OK" or "Cancel".

Also, if I put the confirm() function in a sub-function, like this:

function confirmwrapper() {

    if ( confirm('Are you sure?') ) {
        console.log(1);
    }
}

function myexit () {
    console.log(0);
    confirmwrapper();
}

...it still breaks.

Am I missing something basic here? Respectfully, answers like "just use JQuery/Mootools/some other cool JS library" probably don't help me all that much, because this code is part of a legacy system that I can't completely rip apart right now, much as I want to.

UPDATE: I just tested a simple AJAX request (Mootools Request(), for those keeping score, though I don't think it really matters), and I was able to confirm that the Request is not executed until the confirm dialog is closed--either via "OK" or "Cancel". That's gotta be a bug. Nuts.

Thanks in advance

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

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

发布评论

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

评论(1

变身佩奇 2024-12-12 09:07:01

此时我有点自言自语,但我已经有了“解决方案”(当我说“解决方案”时,我真正的意思是“似乎有效的黑客”),因为我无法使用模态对话来自 JS 库。如果我将confirm()调用放在另一个函数中,并通过setTimeout调用来调用它,这似乎给Safari提供了足够的喘息空间,以允许confirm()之前的代码执行。下面是示例:

function doconfirm() {
    if ( confirm('Are you sure you want to logout?') ) {
        window.top.close();
    }
}

function logout () {
    doCourseSave();
    window.setTimeout('doconfirm();', 500);
}

需要明确的是,“logout()”是在用户操作(单击按钮)时调用的函数。

I'm sort of talking to myself at this point, but I've got "solution" (and when I say "solution" I really mean "hack that appears to work"), given that I can't use a modal dialogue from a JS library. If I put the confirm() call in another function, and invoke that with a setTimeout call, that appears to give Safari enough breathing room to allow the code before confirm() to execute. Here's the example:

function doconfirm() {
    if ( confirm('Are you sure you want to logout?') ) {
        window.top.close();
    }
}

function logout () {
    doCourseSave();
    window.setTimeout('doconfirm();', 500);
}

To be clear, "logout()" is the function which gets invoked on user action (button click).

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