doojinsi has asked for the wisdom of the Perl Monks concerning the following question:

Hail and well met, brethern and sisthern(?!); I wrote a perl CGI app (Win32 and IE only) that does everything the users need to do to transmit financial data to a controlling authority, except press the OK button for them. If the app fails for any reason, the user sees a fatal error page explaining how to resolve the error and that the app must close (always something external to the app). A button on that page closes IE using javascript like this:
print "<P ALIGN=\"CENTER\">"; print "<A HREF=\"javascript:close()\" ALT=\"close this application\">" +; print "<IMG SRC=\"$app_exit_button_img\" WIDTH=103 HEIGHT=103></A></P> +";
But IE is protected from this type of activity, and the user, after pressing the button, sees a popup window that asks if s/he is really sure. Is it possible to code the close with perlscript instead? I'm thinking I could use Win32::OLE to access the current instance of IE and just close it. Am I pursuing the untamed waterfowl here?

Replies are listed 'Best First'.
Re: perlscript to close internet explorer?
by Juerd (Abbot) on Jun 04, 2002 at 20:45 UTC

    Javascript cannot be used, as you have already found out. The Perl is server-side and cannot close a client-side window. Please refer to documents on closing windows with Javascript, as Perl is in this case not the answer. I'm sure something useful can be found at http://www.irt.org/.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: perlscript to close internet explorer?
by joshua (Pilgrim) on Jun 05, 2002 at 04:20 UTC
    Why not just use this?...
    print qq[<script>close()</script>];

    The user won't have to click the link. Instead, it'll just popup the confirm box making sure they want to close the window.

    BTW, Get rid of those nasty_escaped_quotes! : P

    Joshua

      joshua++ for a pragmatic solution. :-)
      ____________

      Makeshifts last the longest.
      hmmm...

      the <script></script> snippet would be called when the fatal error occurred?

      If so, it doesn't exactly follow the flow, which is:

      1. good things happen -> user clicks exit button -> processing shuts down -> user closes browser

      2. BAD things happen -> user sees fatal error screen where s/he must record some info for others to help resolve -> user clicks EXIT button and (hopefully) browser closes.

      If I issue <script>close() when the fatal error occurs, wouldn't this preclude the error screen from appearing? The idea is that s/he MUST do something with the info on the error page.
        Well, I guess you didn't make it clear that it was imperative for the user to see that fatal error until your previous message. I do have another solution though...

        You could open a new window for the processing,
        <form action="process.cgi" method="POST" target="process">
        Then, if there is a fatal error and the user clicks the close window button, IE wont prompt them. (It doesn't prompt on new windows, just their parents.)

        hth.
        Joshua

Re: perlscript to close internet explorer?
by BUU (Prior) on Jun 04, 2002 at 20:56 UTC
    NO. CLOSING USERS WINDOW = BAD. This is a very, annoying thing. And more to the point, is virtually impossible to do. There is a small hack that will do this in IE (well, it used to, doubt if it does any more), and nothing at all that will do it in anyother browser.
      Yep. Lots of references say this is bad. But! I'm the developer and in this case, it's imperative that the app/window close on a fatal error. I should note that there are only a couple of things that are fatal and the users have already expressed annoyance at having to click 2 buttons to close the app, instead of just one. So, this is per request, in addition to just making good sense. Please share the IE hack if you have it, I really need to implement this for just this one app.