Automatically close the browser windows unless such action gets canceled.
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 26 Apr 2015 10:58:52 +0300
changeset 1827f07753959dcf
parent 1826 511463a1733d
child 1829 729dc3c25fd8
Automatically close the browser windows unless such action gets canceled.
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java
     1.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java	Mon Apr 20 10:03:12 2015 +0300
     1.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java	Sun Apr 26 10:58:52 2015 +0300
     1.3 @@ -53,8 +53,16 @@
     1.4          "elem[attr] = value;")
     1.5      private static native void setAttr(Object id, String attr, Object value);
     1.6      
     1.7 -    @JavaScriptBody(args = {}, body = "return; window.close();")
     1.8 -    private static native void closeWindow();
     1.9 +    @net.java.html.js.JavaScriptBody(args = {  }, body = 
    1.10 +        "var a = document.createElement('a');"
    1.11 +      + "a.innerHTML = 'Cancel: closing in 10s...';\n"
    1.12 +      + "a.href = '#';\n"
    1.13 +      + "var closing = window.setTimeout(function() { window.close(); }, 10000);\n"
    1.14 +      + "a.onclick = function() { clearTimeout(closing); document.body.removeChild(a); };\n"
    1.15 +      + "document.body.appendChild(a);\n" +
    1.16 +        "return;\n"
    1.17 +    )
    1.18 +    static native void closeWindow();
    1.19  
    1.20      private static Object textArea;
    1.21      private static Object statusArea;