gpt4 book ai didi

javascript - 更改 Javascript 警报中的文本

转载 作者:行者123 更新时间:2023-11-28 15:57:09 25 4
gpt4 key购买 nike

是否可以在 Javascript 警报出现后更改其中的文本?

例如,是否可以在警报内创建计时器?

┌────────────────────────┐
│ x seconds passed... │
│ <OK> │
└────────────────────────┘

...其中 x 将从 0 更改为传递的秒值。

我知道我可以使用模式或其他东西,但我想知道是否可以在警报框出现后更改文本。

我想这是不可能的,但最好还是问一下。

最佳答案

经过一些初步搜索,似乎不可能做你想做的事。我认为这主要是出于安全原因。

不建议使用警报框,因为 ( WebPlatform ):

  • This is a synchronized method call. Meaning, calling this method pauses scripting execution of the window from which this method is called, until the user closes the displayed dialog. Also, depending on your cross tab/window usage, this can sometimes pause scripting executions of other windows/tabs from the same domain.
  • Calling this method in some browsers prevents the user from interacting with the entire browser, or browser window (along with all of its tabs), until the dialog is closed.
  • Intrusive dialog boxes are generally annoying for the user.
<小时/>

您可以使用以下之一创建自己的对话框:

您总是可以收到一条警报:“嘿,看这里,用户,我想告诉您一些事情!”然后使用上述之一。

<小时/>

另一种选择是使用 JavaScript 创建弹出窗口

window.open("http://example.com");

您可以使用showModelDialogshowModelessDialog

您可以在哪里使用 dialogArguments , dialogHeight , dialogWidth , dialogLeft ,和dialogTop .

但问题是大多数人都有弹出窗口拦截器,它们会阻止您无辜的弹出窗口。

<小时/>

仅 ActiveX 的可能性似乎是 Modified Alert Box 。我没有对此进行测试,因为我没有 Windows 计算机。

<小时/>

还有nsIPromptServicealert和/或 alertCheck 。这些似乎提供了更多功能,例如添加标题或复选框。还有提示、选择等。

不幸的是,这个似乎在 Javascript 中不可用。似乎它仅适用于 Firefox 扩展等(Chrome 用户)。

关于javascript - 更改 Javascript 警报中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18327643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com