Question
· Aug 8

Can't close CSP popup window

I am writing a little app where I press a button on a Zen form. It calls a ZenMethod that uses zenPage.launchPopupWindow() to provide me a way to choose a file. I then click on an upload button that calls a csp cache language script file that runs on the server, that grabs the contents of the file and stuffs it into a global. I want it then close and return to the parent window to continue processing the contents of the file. I have tried placing the javascript code that closes the window and calls a function in the parent window in different places, but it is not closing the window or calling back to the parent window. I have pasted the contents of the CSP page. I am hoping someone can help me with what I am doing wrong.

This is based on upload.csp in the SAMPLES namespace

<!-- Copyright (c) 2001 InterSystems Inc. ALL RIGHTS RESERVED. -->
<csp:class description="Upload Client Consultations file.">
<html>

<head>
<script language = "JavaScript" >
 function exitPopup() {
    opener.processImport();
    window.close();
}
</script>
</head>

<body bgcolor="#CCCCFF">

<!-- HTML Form to submit the file. You must specify the enctype="multipart/form-data" -->
<!-- for this to work -->
<form enctype="multipart/form-data" method="post" action="upload.csp">
    Choose Client Consultation file: <input type=file size=30 name=FileStream>
    <p>
    <ul><input type="submit" value="Upload file"></ul>
    <p>
</form>

<!-- As form is submitted to this page look to see if we have the stream in the %request object -->
<csp:if condition='($data(%request.MimeData("FileStream",1)))'>
    <ul>
    <script language="Cache" runat="server">
        New bytes
        Set bytes=%request.MimeData("FileStream",1).Read()
        Set bytes=##class(%CSP.Utils).DecodeData(bytes)
        If $Data(^CacheTemp("UploadedCSV")) Kill ^CacheTemp("UploadedCSV")
        Set ^CacheTemp("UploadedCSV")=bytes
        &js<exitPopup();>
    </script>
    </ul>
</csp:if>
</body>
</html>

 

Thank you for your time

Product version: Caché 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.7 Fri Mar 8, 2022 22:24:36 EDTCacfhCache
Discussion (1)2
Log in or sign up to continue

It appears you are facing a challenge with invoking JavaScript code to close a pop-up window and calling a function in the parent window from your CSP page. Below are some suggested approaches to resolve these issues:

  1. Using JavaScript window.close and opener: To ensure the parent window interacts with the child pop-up window, you can utilize window.close along with opener.<functionName>. Make sure the parent window's function is callable via the opener. For example:

    function exitPopup() {
       opener.processImport();
       window.close();
    }
    

    This ensures the parent window's processImport function is invoked before the window is closed [1].

  2. Handling the onunload Issue: If the onunloadHandler is not firing or behaving inconsistently, ensure the modal behavior is explicitly managed. The approach might depend on the settings of useSoftModal, as the behavior of launchPopupWindow can vary when this setting changes. Testing to confirm the modal window behavior under different browsers, including Edge, is critical [2][1].

  3. Calling ZenMethods on Page Unload: Ensure ZenMethods are configured properly for synchronous calls during the onunloadHandler execution:

    var old = zenSynchronousMode;
    zenSynchronousMode = true;
    this.SomeZenMethod();
    zenSynchronousMode = old;
    

    This ensures the method is executed synchronously during page unload [1].

If further clarification or assistance is required, especially considering unique configurations and browser compatibility issues, please consult the Developer Community for detailed guidance.

Sources: