替代JavaScript的提示()适用于Google Chrome Web App [英] Alternative to Javascript's prompt() for Google Chrome Web App

查看:138
本文介绍了替代JavaScript的提示()适用于Google Chrome Web App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Chrome平台API 和Javascript开发Chrome Web应用程序和我根本无法找到一种方法来显示提示()对话框以向用户询问值,以防止他在任何其他地方点击,直到他输入值并接受或取消(这意味着,它完全如何与Javascript一起工作)。



我的问题是,我无法找到一种方法来使用Chrome平台API来做到这一点(注意提示(),alert()和confirm()不能在打包应用程序中使用)。我已经检查了与我的类似的问题,并且他们都指向Google应用服务脚本文档,该文档不适用于Chrome应用。

我真正发现的唯一解决方案是创建一个新窗口,使单身人士能够成为它的一个实例并在那里显示一个表单,在用户接受时获得值(我还没有真正完成最后一部分,我需要一种方法来检查窗口何时被按钮关闭)。尽管如此,这对于简单的对话还是很有用的。

是否有一种简单的方法可以做到这一点,即我错过了或是预期的方式来使用多个窗口?

解决方案

window.prompt 有两个功能:


  1. 它会向用户请求输入。

  2. 它以同步方式执行此操作,即执行页面中的JavaScript被暂停,直到 prompt()返回。

,但第二个功能不能。所以,你将能够获得用户输入,但只能以异步方式。有两种提示用户输入的方法:


  1. 在弹出窗口中显示。


灯箱与弹出框类似,只不过它嵌入页面本身。一个灯箱的所有实现都至少包含两个容器:


  1. 覆盖整个页面的div,以便用户无法点击其他任何内容。 (CSS: position:fixed; top:0; left:0; width:100%; height:100%; z-index:1000;

  2. 其他类似于对话框的HTML元素(输入字段,按钮)。

现有大量UI库来显示内联对话框,例如 jQuery UI


I'm currently developing a Chrome Web App using the Chrome Platform APIs and Javascript and I simply can't find a way to display a prompt() dialog to ask the user for a value, in a way that prevents him from clicking anywhere else until he enters a value and accepts or cancels (meaning, EXACTLY how it works with Javascript).

My problem is, I just can't find a way to do this with the Chrome Platform APIs (note that prompt(), alert() and confirm() can't be used in packaged apps). I already checked questions similar to mine and they all point to the Google App Script documentation, which doesn't work for Chrome Apps.

The only "solution" that I've really found is making a new window, enabling singleton so that it can only be an instance of it and displaying a form there, getting the value when the user accepts(I haven't really finished that last part, I need a way to check when the window is being closed by a button). Still, this is kind of a lot for a simple dialog.

Is there a simple way to do this that I'm missing or is the "intended" way to do this to use multiple windows?

解决方案

window.prompt has two features:

  1. It requests input from the user.
  2. It does this in a synchronous way, i.e. execution of JavaScript in your page is suspended until prompt() returns.

The first feature can be emulated, but the second feature cannot. So, you will be able to get user input, but only in an asynchronous way. There are two ways to prompt the user for input:

  1. In a popup.
  2. In a lightbox.

A lightbox is similar to a popup, except that it's embedded in the page itself. All implementations of a lightbox involve at least two containers:

  1. A div that covers the whole page, so that the user cannot click on anything else. (CSS: position:fixed;top:0;left:0;width:100%;height:100%;z-index:1000;)
  2. Other HTML elements that together resemble a dialog (input fields, buttons).

There are plenty of existing UI libraries to show an inline dialog, e.g. jQuery UI.

这篇关于替代JavaScript的提示()适用于Google Chrome Web App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆