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


Groups > comp.lang.javascript > #31320

Re: restore window alert

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: restore window alert
Date 2016-09-11 13:24 +0200
Organization PointedEars Software (PES)
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>

Show all headers | 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