vbNewbie
vbNewbie

Reputation: 3345

close pop up window after form request submit

I have an application that plays back video within a browser window. If the video type is not compatible in html5, then the option is to download with a button as I cannot get the chrome video control to remain on the page in that case. Once the button is clicked the video is downloaded and played in media player. I need to be able to close the original pop up window when this happens.

   function playScreen(){
        var playScreenForm = document.getElementById('playScreenForm');
        playScreenForm.action="/playback/exportVideo.action?type=video";
        document.getElementById('videoID').value = getSelectedVideoID();
        document.getElementById('custID').value = getSelectedCustID();
        playScreenForm.submit();
        window.close()
   }

If I do it this way, the windows does in fact close but too early and the playback does not occur. The other issue I am having is that once the window opens and the user perhaps minimizes the window or focusses on another, it loses focus if the user clicks to play another video & does not appear in focus. The following does not work, except the blur function which will close the window the minute the user clicks anyway outside, but this is not ideal. I just listed the functions I have tried below.

   window.addEventListener('blur', function(){
        console.log('blur');
        window.focus();
        window.close();
    }, false);

    window.addEventListener('minimize',function(){
        window.focus();
        window.close();
    }, false);


    window.addEventListener('focus', function(){
        console.log('focus');
        window.focus();
    }, false);

Any ideas or suggestions?

This is what appears even after adding the setTimeout functions;

pop up

the white window in the background is the one I am trying to close.

 <button class=button id="buttonLink" type="button" style="display:none; 
    position:absolute;margin-left:80%; width:120px;bottom:7px;" 
    onclick="playScreen()">Download</button> 
 <form METHOD="POST" id="playScreenForm" >
    <input id="formID" name="formID" type="hidden" value="playScreenForm"/>
    <input id="callID" name="ID" type="hidden"/>
    <input id="recID" name="CustID_Type" type="hidden"/>
  </form>

Upvotes: 1

Views: 1812

Answers (2)

Justinjs
Justinjs

Reputation: 140

Solution to your first question : setTimeout(function(){ window.close(); },5000);

use javascript timeout function and set your desired time

example : 5000 = 5 seconds demo for opening a window and closing it after 5 seconds delay

Upvotes: 1

Lajos Arpad
Lajos Arpad

Reputation: 77083

You have stated two problems, let's focus on the first only. You may ask the second as a separate question. The first problem is that your window closes too early, so it works, but you are not satisfied with the UX. You will need to postpone the closing of the window to make it happen after the playback occurs. Assuming that you have a variable called playback, which holds the number of seconds you want to wait before the window is closed, you could so something like this:

   function playScreen(){
        var playScreenForm = document.getElementById('playScreenForm');
        playScreenForm.action="/playback/exportVideo.action?type=video";
        document.getElementById('videoID').value = getSelectedVideoID();
        document.getElementById('custID').value = getSelectedCustID();
        playScreenForm.submit();
        setTimeout(function() {
            window.close();
        }, playback);
   }

If you have a function which runs at the end of the playback, you could handle the closing of the window there.

Upvotes: 1

Related Questions