I have a pop-up window from an exiting application that I want to trap inside a lightbox using an iframe. This is working well except for one thing.
When the pop-up is "done", it calls Window.Opener to reload the parent window. I want to override this so that I can do something else when it attempts to call this function.
I'd prefer to override this vs. modify the pop-up's code, making changes to the existing application is... no fun :)
Open an intermediate window and call the pop-up from there. The intermediate window is now the "opener", so it will leave the actual parent window alone.
Related
Is there a way in jquery and/or javascript to create a pop up window that can directly effect a parent window in a browser? In my case I want to set up a GUI in the pop up which can move objects in the parent window left/right/up/down. I also need this to work in a dual monitor setting. Any leads on how to do this would be great!
Functions in the child window can control the parent window by using parent. for example:
parent.alert("moo");
You can use window.opener to interact with the opening window, since it sounds like you want to open a new window. So if you have a javascript function declared in the opening window as
function test(){
alert("I'm the parent!");
}
you can call it from a popup window by calling
window.opener.test();
The requirement here is that both the opening window and the open window must be either in the same domain or at least subdomain. If it is the same subdomain, a little work is needed to allow the cross-domain access, which you can read more about here https://stackoverflow.com/a/3962489/1558122.
You would initially open the popup of course by calling window.open from the parent, and dual monitor should not affect the behavior here.
What you really want is probably a dialog, not a window. Windows are cumbersome and require all the HTML a document requires. You could try this jquery plugin: http://jqueryui.com/dialog/ . A dialog requires minimal HTML.
I confess I don't know about the dual-monitor thing.
I have a requirement that I need to create a link to open a form in a new window and then when I click the same link it will focus on the existing window again.
this works well with the following code
<input type="button" value="Click" onclick = "return OpenWindow();"/>
<script>
var win = null;
function OpenWindow()
{
if (win == null || win.closed)
{
win = window.open('http://localhost/Conditions.aspx', 'Condition');
}
win.focus();
return false;
}
</script>
However, I experienced a problem, when I switch to different page and come back to the page which has the link. the variable win will not retain the previous reference.
If I click the link again, it will refresh the existing window (which is not what I want!) and then focus on it.
Is there any way that I can keep variable reference? or does anyone know how to solve this problem?
I had the same issue and was resolved on Window.open only if the window is not open
If you basically want the window focused instead of refreshed when the link is clicked, even if the parent window has been closed, re-opened, or changed, this will do the trick.
I was about to resort to using cookies.
Chia, your problem is that JS doesn't persist across pages.
HTML is stateless, so the JS that sits on top also needs to "forget" what it did on page-1, after you move on to page-2 and page-3.
There are ways of storing strings and numbers, and retrieving them on other pages, but that's not what you're looking for.
And to that end, there's nothing you can really do, with your current setup.
There are different ways of allowing you to keep the child reference (do main-page navigation inside of an iFrame in the main page... if you really, really have to... or AJAX in the page changes, for people with capable browsers, and use old-fashioned navigation for browsers with worse JS engines).
But it's not going to be possible for you to open window2, click on a link which points window1 at page3, and still have page3 have a reference to window2.
Ok so if I create a window in JavaScript and the parent page changes like to a search page how can I handle the popup window from the page before?
Just call window.open with the same name (second parameter). It will give you back that window instance if it's still open instead of opening a new one.
Not sure what you mean by 'handle'?
However if you want to add content, close the window, give it focus, etc look at the Window Object Methods here: https://developer.mozilla.org/en/DOM/window
Can you be a bit more specific about what you want to do or are try to achieve?
I have a window which uses javascript to open another child window, in the standard window.open("http://foobar","name") manner. If I open again with the same name, it reuses the window. This is great and exactly what I want.
However, if the original window is closed, I would like to be able to reopen it and have its window.open go to the previously opened child window. Unfortunately, because it is a new parent window it will open another child window (which it will happily and correctly reuse).
Does anybody here know of a way to get hold of that previous child window so I can avoid making more windows than necessary?
Behind the scenes, the driver of this question is this: I have a java program which will periodically open different websites and I do not want to force a plethora of tabs or windows. Command-line options do not let you reuse windows or declare targets; javascript lets you declare a target. I figured I would write a small javascript page which opened a page in a specifically-named window and then close itself. Anytime you want to see a new page, hit that page passing in your new page.... Much to my dismay, though, targets seem specific to the window which creates them.
So if you have ideas which are relevant to my actual problem I'm interested too.
Embedding a browser took less time than trying various ways of controlling browsers.
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.