HTML transient modal window

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 09:33:10

问题


We have a legacy web application. At various places it opens a window with the help of Privilege Manager on Firefox to get the needed result. Some of these windows open a Java applet or a PDF document. The client machines are updating Firefox and Privilege Manager is gone.

What is the easiest way around it? The problems are :

  1. There must be only one instance of the pop-up at anyone time. This could be done by selecting appropriate window name on window.open() call.

  2. If the window is opened again (by means of user action), it should not reload but just focus to bring it to the foreground (I have seen I can keep a reference to the window on JavaScript to do that)

  3. It basically really must be transient/modal so that the client cannot leave the current page or reload or any other kind of interaction with the parent window (except opening/refocusing the child window) without closing the child window first. I have no idea how to do that.

Do anyone has an idea how to do that?

The client is only Firefox (it works in a special kiosk configuration) on Linux.

I read somewhere that I could somehow write an extension but I am basically clueless about extensions and its API.

Edit1:

Example of (simplified) legacy code. Not really sure if all the permissions were required, but this is it: This function opens a window that stays over the parent window and prevents any interaction from the user with the parent 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();"/>

Edit2: Solution

On a typical extension, on the xul code, define this javascript code:

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);

Then, on the web page:

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);

Now, maybe I am missing some security checks to let the code work if it originates from the same host, and how to handle a reference to the document that requested the dialog as means of interaction between the dialog window and it's opener.


回答1:


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

You might want to look into Window.showModalDialog(). However, it is deprecated and is expected to go away within the year, or in 2016 if you go with an extended service release (ESR) of Firefox 38. It may be a temporary solution while you develop an extension.

In order to accomplish the same tasks, you will need to write an extension and ask the user to install it (from Bypassing Security Restrictions and Signing Code, the old information about Privilege Manager):

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

It is possible to write such an extension using any of the three different extension types:

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

For the first two types, you would use window.open(). The modal option is in "Features requiring privileges". You will probably also want to look at Window.openDialog().

For the Add-on SDK, you would normally use the open() function in the SDK's window/utils module. Here, again, you will probably want to look at openDialog().

It appears you may be opening content that is supplied from the web in these modal windows. It is unlikely that you will get an extension approved to be hosted on 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".




回答2:


You should be able to get similiar window.open behavior, including support for the modal option from the sdk's window/utils module.

You will have to install the onclick listener with a content script, send a message to the addon-main through its port and then open that window from the addon main.



来源:https://stackoverflow.com/questions/29037807/html-transient-modal-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!