避免浏览器中涉及 Ajax 事件的弹出窗口阻止的最佳实践

发布于 2024-11-29 01:36:44 字数 358 浏览 1 评论 0原文

我知道这听起来可能与 SO 上的几个问题类似,但不知怎的,它们并没有以任何最佳实践说服我。

现在我知道,在使用 AJAX 时,这是一个非常简单的建议,永远不要选择同步 XHR。但是,如果 XHR 是某些验证标准的一部分,如果成功,则必须打开一些弹出窗口,该怎么办?当异步 XHR 被调用时,用户事件就结束了。如果浏览器做得很好,原本打算在回调中打开的弹出窗口将永远不会发生。

在这种情况下,应该有什么好的解决方法可以满足最佳实践。

我读过的一种干净的解决方案是立即打开弹出窗口并更改其在回调中的行为。现在,这当然可以与需要保留直到我们进入回调的额外状态一起使用。还有比这更好的解决方案吗?或者,如果不会造成太多麻烦,理智的人应该坚持使用同步 XHR 吗?

I know this might sound similar to a few questions on SO already, but they somehow don't convince me with any best practice.

Now I know, its a pretty straightforward advice while using AJAX, never (ever) go for Synchronized XHR. But what if that XHR is part of some validation criteria which if succeeds has to open some popups. The moment the asynch XHR is invoked, the User Event has ended. The Popups that were intended to open in the callback will never happen if the browser is doing its job well.

What should be nice workaround that might settle for best practice in such scenario.

One clean solution that I've read is to open the popups right away and change their behavior in the callback. Now this may work ofcourse with extra state that needs to retained till we enter the callback. Is there a better solution out there than this? Or should the saner minds stick to Synchronized XHR if its not causing too much trouble?

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

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

发布评论

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

评论(1

許願樹丅啲祈禱 2024-12-06 01:36:44

我读过的一个干净的解决方案是立即打开弹出窗口并在回调中更改其行为。

当我看到你的问题标题时,这就是我的答案。

现在这当然可以与需要保留直到我们进入回调的额外状态一起使用。

将回调声明为创建弹出窗口的函数内的闭包。它将继承所有状态并且浏览器不会锁定。

One clean solution that I've read is to open the popups right away and change their behavior in the callback.

That was going to be my answer when I saw the title of your question.

Now this may work ofcourse with extra state that needs to retained till we enter the callback.

Declare the callback as a closure within the function that creates the pop-up. It will inherit all the state and the browser won't lock up.

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