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 window 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;
}
Related
In my wordpress site, some hacker has embedded a script into it somewhere.
The problem I'm having now is, whenever the site is opened, the first time a user clicks anywhere on it, a spam popup appears, due to the hacker's script.
Is there any way I can prevent the popup window from being created with Javascript?
If I can't prevent it, is there any way that I can close the popup using JS? Unfortunately, since the other script is creating it, I don't have a reference to the opened window. I've seen other scripts calling .close() on an opened window, but I don't have a reference to the new window, so I don't know how to close it.
Here's my site.
The popup on your site is opened by something calling window.open. You can prevent it by assigning something else to window.open and running your script before the other script does:
window.open = () => undefined;
(This does work, if I run this code on your site before your site's Javascript runs, no windows get opened)
It's not uncommon for a client to want to implement this, but if you're the server, it'd be better to fix the server to remove the malicious code, rather than try to patch around it.
After making a rest request to a webservice, I want to redirect my user to the url returned by the web service.
I am using window.open(url, "_blank"); which has, when I've used it in the past, simply opened up a new tab. However, for some reason that I can't get to the bottom of, my redirect is being treated as a popup. Instead of opening a new tab, Chrome actually creates a separate small window.
I'd be grateful for any suggestions as to why chrome would decide to create a separate window as opposed to just opening a new tab.
Thank you
Check out this response from another question. When a javascript event is initiated by the user, open() opens the link in a new tab. Otherwise, it's opened in a popup window. So if the user clicks something that triggers open(), a new tab will open. If you set a timeout or try to open a link after some other event, like an ajax response, a new window will open.
We have a Master page and some child pages.One in them is popup by window.open function.The problem occurs When logout is clicked at Master Page.whole System is redirect to Login page except that Popup window.when i clicked on that child-page then it will redirected to Login Page.We need it be closed directly after logout is pressed.
Is there any script to close window if the window's location is known.I want to close that child page in Logout click.
like window.close('Authentication.aspx');
please tell me if it is possible
Thanks ,
Rakesh.
If you've opened a popup window using the following code, with a presumed name of "popupwindow"...
window.open("myurl.html", "popupwindow", "height, etc");
Then in your login page try the following javascript
if(window.name=="popupwindow"){
window.close();
}
UPDATE based on comments by OP...
If you no longer have a reference to the window (because the parent window has refreshed for example), then I believe it is almost impossible to detect whether a popup window with a particular name exists or not.
I say "almost impossible" because one option in this situation is to try opening the window again giving a blank URL. If the window already exists, then the window will remain on the same page as before, but now you have a reference to it, and can close as necessary.
var myWin = window.open("","popupwindow");
myWin.close();
However, the downside to this is that if the window does not exist, the user will see a blank window open before then being closed - so not a nice user-experience.
I am using FuncUnit to test a small application I wrote. I have a button that will open a popup window (using the JavaScript function window.open(...)). I can get FuncUnit to press the button and open the pop up window,but I'm not sure how to proceed in order to get a handle on the popup window and do further testing.
Unfortunately, I cannot change any of the code in the pop up,
Thank you,
Matt
open returns a reference to the created window's window object. So you can simply use that to access anything in the window. Not sure if you can verify that it has finished loading if you can't modify the popup. Also note that both windows must be on the same domain in order for you to access it.
I have a webpage (popup) with flash content. When a user clicks a button inside the flash content, it opens up another browser popup window. Next, I need to close the window with flash content from the newly opened popup window through javascript.
The problem is that the window.Opener is null as the popup is invoked inside from flash content. Moreover we dont have access to flash (.FLA) file.
Please help me to get around this.
With ExternalInterface, have your Flash code call openPopup() and closePopup() JS functions in the original window. These functions can keep track of the opener handle.
BTW, popup windows are bad. They are hard to work with, hated by users, and thwarted by browsers. If your client insists, then talk your client out of it. Use an Ajax dialog instead.