JavaScript DOM Window - javascript

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?

Related

How to create a pop up browser window that contains a GUI and controls a parent browser window

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.

How to make popup window in javascript only show once?

I want to make single pop up window in javascript. No matter how many times the button is pressed from parent page, only the single pop up is activated.
How can I do that in Javascript?
Just give the window a fixed name. So, don't do
window.open('popup.jsp');
but do
window.open('popup.jsp', 'chooseHereYourFixedName');
It will then be reused.
The window.open method takes 3 parameters.
a URL
a Name
a list of arguments
As long as the Name portion is the same when you open the popup, the same window will be reused.
window.open ("http://www.google.com","mywindow","status=1");
Here's another idea.
Why not create an inline page popup (div) with an iFrame inside? Fancybox does this pretty easily along with a number of other frameworks. Pretty easy to write with custom Javascript as well.
This way your users will never navigate from your window and only that popup will ever live from clicking the button.
<script>
var popup;
</script>
<input type="button" onClick="if (!popup) popup = window.open('new.html');">

Using funcunit to test a popup window

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.

How can I modify this bookmarklet to work on a tab instead of a new window?

When you put this in your browser it opens a simple notepad to type in.
I don't know enough about javascript to alter it but I would like to make it so it DOESN'T open in a new window but rather in the current window or another tab.
Is this even possible?
javascript:pwin=window.open('','_blank','menubar=yes,scrollbars=yes,location=no,height=450,width=350');pwin.document.body.contentEditable='true';pwin.document.designMode='on';void(0);if(window.focus){pwin.focus()};
Technically, window.open does not always open in a new window. You can use _self instead of _blank, and it will open in the same window. Or use _parent and it will open in the current frame's parent.
Window.open always opens this in a new window.
Instead I think you can try window.location. Not tried tough.
Ok did a little digging and there is nothing you can do that will guarantee that it will open in a new tab. However if you remove the width and height parameters some browsers will open in a new tab if user preferences haven't overridden this behavior. See this post (2nd answer in list) Stackoverflow post
If you aren't looking to open a window, then don't window.open()
Setting window.location should do the trick, as pointed out by Sachin

Override JavaScript Window.opener

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.

Categories