HTML 瞬态模态 window

HTML transient modal window

我们有一个遗留的网络应用程序。在 Firefox 上的权限管理器的帮助下,它会在不同的地方打开一个 window 以获得所需的结果。 其中一些 windows 打开 Java 小程序或 PDF 文档。 客户端计算机正在更新 Firefox,而权限管理器已消失。

最简单的解决方法是什么? 问题是:

  1. 任何时候都必须只有一个 pop-up 实例。这可以通过在 window.open() 调用中选择适当的 window 名称来完成。

  2. 如果 window 再次打开(通过用户操作),它不应该重新加载,而只是专注于将它带到前台(我已经看到我可以保留参考到 Java 上的 window 脚本)

  3. 它基本上必须是 transient/modal 这样客户端就不能离开当前页面或重新加载或与 parent window 进行任何其他类型的交互(除了 opening/refocusing child window) 而不是先关闭 child window。我不知道该怎么做。

有人知道怎么做吗?

在 Linux.

上客户端只有 Firefox(它在特殊的 kiosk 配置中工作)

我在某处读到我可以以某种方式编写扩展,但我对扩展及其 API 基本上一无所知。

编辑1:

(简化的)遗留代码示例。不确定是否需要所有权限,但就是这样:此函数打开一个 window,它位于 parent window 之上,并阻止用户与 [=66] 进行任何交互=] window.

function fWindowOpen(url, name) {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
    netscape.security.PrivilegeManager
            .enablePrivilege("CapabilityPreferencesAccess");
    netscape.security.PrivilegeManager
            .enablePrivilege("UniversalPreferencesWrite");
    netscape.security.PrivilegeManager
            .enablePrivilege("UniversalPreferencesRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    window.open(
        url,
        name,
        "screenX=70,dependent=yes,menubar=0,toolbar=0,width=900,height=700,modal=1,dialog=1"
        );
}

function fnCapture(){
    fWindowOpen("/path/to/document_or_japplet/page","_blank");                      
}

HTML:

<button value="Capture" property="btnCapture" onclick="javascript:fnCapture();"/>

编辑 2:解决方案

在典型的扩展上,在 xul 代码上,定义这个 javascript 代码:

var dialogExt = {
 listener: function(evt) {
  // Do work with parameters read through evt.target.getAttribute("attribute_name")
  window.openDialog(evt.target.getAttribute("url"), evt.target.getAttribute("name"), evt.target.getAttribute("features"));
 }
}
// from examples
document.addEventListener("dialogExtEvent", function(e){ dialogExt.listener(e); }, false, true);

然后,在网页上:

var element = document.createElement("dialogExtElement");
element.setAttribute("url", url);
element.setAttribute("name", name);
element.setAttribute("features", features);
document.documentElement.appendChild(element);
var evt = document.createEvent("Events");
evt.initEvent("dialogExtEvent", true, false);
element.dispatchEvent(evt);

现在,如果代码来自同一主机,我可能缺少一些安全检查来让代码工作,以及如何处理对请求对话框的文档的引用作为对话框之间的交互方式 window 这是开场白。

您应该可以获得类似的 window.open 行为,包括对来自 sdk 的 window/utils 模块的 modal 选项的支持。

您必须使用 content script 安装 onclick 侦听器,通过其端口向插件主体发送消息,然后从插件主体打开 window。

Privilege Manager was deprecated in Firefox 12 and removed in Firefox 17 (briefly restored).

您可能想查看 Window.showModalDialog()。但是,它已被弃用,预计将在今年内消失,如果您使用 Firefox 38 的扩展服务版本 (ESR),则可能在 2016 年消失。这可能是您开发扩展时的临时解决方案。

为了完成相同的任务,您将需要编写一个扩展并要求用户安装它(来自 Bypassing Security Restrictions and Signing Code,有关权限管理器的旧信息):

Sites that require additional permissions should now ask Firefox users to install an extension, which can interact with non-privileged pages if needed.

可以使用三种不同的扩展类型中的任何一种来编写这样的扩展:

  1. XUL overlay
  2. Restartless/Bootstrap
  3. Add-on SDK

对于前两种类型,您将使用 window.open(). The modal option is in "Features requiring privileges". You will probably also want to look at Window.openDialog()

对于附加 SDK,您通常会使用 open() function in the SDK's window/utils module. Here, again, you will probably want to look at openDialog()

您可能正在这些模式 windows 中打开从网络提供的内容。您不太可能获得批准在 AMO which opens content in such windows which in not included in the add-on release. This does not mean you can not develop the extension and have it installed on your kiosk clients without hosting it on AMO. However, there are additional restrictions in development for Firefox this year which will make this significantly more difficult, see: "Introducing Extension Signing: A Safer Add-on Experience".

上托管的扩展程序