开发者

Help with accessing a pre-existing window AFTER opener is refreshed!

开发者 https://www.devze.com 2022-12-25 08:39 出处:网络
Alright, I\'m at my wit\'s end on this issue. First, backstory. I\'m working on a video management system where we\'re allowing users, when adding new content, to upload and, optionally, transcode a

Alright, I'm at my wit's end on this issue.

First, backstory. I'm working on a video management system where we're allowing users, when adding new content, to upload and, optionally, transcode a media file. We're using Java applet for the browser-based FTP client.

What I want to do is allow a user to initiate an upload and then send the FTP connection instance to a popup window. This wind开发者_StackOverflow社区ow will act as a job queue for the FTP transfer process. This will allow users to move about the main interface without having to stay on the original page until an individual file transfer is complete.

For the most part I have all of this working, but here's a problem. If the window is closed, all connections are dropped and the upload process for all queued files will be canceled.

So, if Window One opens the Popup Window, adds stuff to the queue, refreshes the screen or moves to a different page, how will I access the Popup Window?

The popup window and its contents must remain persistent while the user navigates through the original window. The original window must be able to access the popup to add a new job to the queue. The popup window itself is independent of the opening window, so communication only happens in one direction:

Parent -> Popup

Not

Parent <- Popup

Window.open(null, 'WINDOW_NAME'); will not work in this case. I need to check if a window exists BEFORE using window.open.

Help!?!?


SOLVED!!!

Here's what I did. In the popup window, I added an arbitrary variable. The parent window checks for the existence of this variable. If it's defined, then the window must be open. If not, then open a new window.

The way this works is I just use window.open(null, 'WINDOW_NAME') to open a very tiny browser window. If you don't specify a URL, it will either:

A) Open a blank window B) Focus the existing window

It then checks for the variable. If it doesn't exist, it closes the window and returns 'false'. If it does, it focuses the existing window and returns 'true'.

function isWindowOpen(targetWindowName)
{
    tempTargetWindow = window.open('', targetWindowName, 'width=1,height=1');

    if(typeof(tempTargetWindow.thisWindowExists) == 'undefined')
    {
        tempTargetWindow.close();

        return false;
    }

    return true;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号