Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31320

Re: restore window alert

Path csiph.com!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: restore window alert
Date Sun, 11 Sep 2016 13:24:57 +0200
Organization PointedEars Software (PES)
Lines 83
Message-ID <19142186.EfDdHjke4D@PointedEars.de> (permalink)
References <toydnbeQVIupLk3KnZ2dnUU7-KXNnZ2d@westnet.com.au> <18kx87e56fmrr.u0ghv1tkc6cu.dlg@40tude.net> <92e03e5f-e115-40d1-ba94-4b34459d8c14@googlegroups.com> <1760285.oMNUckLgyt@PointedEars.de> <I5ydnQOkHc6DgEjKnZ2dnUU7-KPNnZ2d@westnet.com.au>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1473593098 12717 eJwFwYEBwCAIA7CXBqVgz3Gg/59gQqRlVyQzeHm3nW9cquPrQAp6gKsNitqtXIYfqJ1DjdcDAyQP/A== (11 Sep 2016 11:24:58 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Sun, 11 Sep 2016 11:24:58 +0000 (UTC)
User-Agent KNode/4.14.2
X-NNTP-Posting-Host eJwFwQkBwDAIA0BLfAlUTunAv4Tdwal8GQQDi43EXZv6fA5rpab9kWEqi0ht9Tbg5mmKlv0T+xBF
Cancel-Lock sha1:c/pkcQZcMGbf2k7m7L6BYmziYtA=
X-User-ID eJwFwQEBwCAMAzBL9LQdyNmA+ZfwRNPwCVqmWv06RiSXsGbVVylmI1R8uJ49zkkI2lGlKzufm5cYXNTGD1apFSo=
Xref csiph.com comp.lang.javascript:31320

Show key headers only | View raw


Andrew Poulos wrote:

> This in Edge when run locally
> 
> <!DOCTYPE html>
> <html>
> <head>
> <meta charset="utf-8">
> <title>Alert</title>
> <script type="text/javascript">
> var _alert
> 
> function show() {
>    var w = window.open();
>    _alert = w.alert;
>    w.close();
> 
>    window.setTimeout(function() {
>      window.alert = _alert;
>      window.alert(42);
>    }, 300);
> }
> </script>
> </head>
> <body>
> <p onclick="show()">Hey</p>
> </body>
> </html>
> 
> results in a new tab being opened and closed but no alert box appearing.

Different problem; I did not say “window.setTimeout”.  Also, you want to use 
the module pattern.

But Edge 25.10586.0.0 on Windows 10 Enterprise Evaluation, Version 1511, 
Build 10586.164, at least does have the problem that you cannot call the 
transferred “alert” method: you get “Invalid calling object” when you try.  

Internet Explorer 11.162.10586.0 behaves differently there: Depending on 
whether you close the popup before calling its alert() or afterwards, you 
get either “Invalid calling object” or “Function expected” or nothing.  I 
might look into this further when I am back in the office: debugging Edge/IE 
11 on Windows 10 in VirtualBox on OS X via TeamViewer is a PITA.

For now, something along the lines of

  var iframe, w, d, b;
  var _alert = (typeof document.createElement != "undefined")
    && (iframe = document.createElement("iframe"))
    && (iframe.style.display = "none")
    && (b = document.body)
    && (typeof b.appendChild != "undefined")
    && (b.appendChild(iframe) || true)
    && ((w = iframe.contentWindow) && w.alert
        || (d = iframe.contentDocument)
            && (w = d.defaultView)
            && w.alert))
    || (function () {
         var w = window.open("", "w" + new Date().getTime(),
                             "width=1,height=1");
         if (!w) return null;

         var local_alert = w.alert;

         w.close();

         return local_alert;
       }());

  if (_alert)
  {
    window.alert = _alert;
    window.alert(42);
    b && b.removeChild(iframe);
  }

is probably the safest bet.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

restore window alert Andrew Poulos <ap_prog@hotmail.com> - 2016-09-08 10:39 +1000
  Re: restore window alert "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-07 18:00 -0700
  Re: restore window alert JJ <jj4public@vfemail.net> - 2016-09-08 18:47 +0700
    Re: restore window alert "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-08 06:43 -0700
      Re: restore window alert Martin Honnen <martin.honnen@gmx.de> - 2016-09-08 16:32 +0200
        Re: restore window alert Andrew Poulos <ap_prog@hotmail.com> - 2016-09-09 14:49 +1000
          Re: restore window alert "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-09 06:20 -0700
      Re: restore window alert Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-10 16:26 +0200
        Re: restore window alert Ram Tobolski <ramtob@gmail.com> - 2016-09-11 00:17 -0700
          Re: restore window alert Andrew Poulos <ap_prog@hotmail.com> - 2016-09-11 17:57 +1000
          Re: restore window alert Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-11 11:19 +0200
        Re: restore window alert Andrew Poulos <ap_prog@hotmail.com> - 2016-09-11 19:00 +1000
          Re: restore window alert Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-11 13:24 +0200

csiph-web