can browser popout windows be launched (like google talk conversation windows can be popped out into a new window from the main gmail page.) so they are still part of the main page i.e. share resources and access and modify each other, e.g. if the popout window contained a button it can be clicked and modify part of the original page without having to go to the server? I'm guessing the answer is no, but as I don't know for sure I thought I'd ask.
You can access the popout parent by using the window.opener property from within the 'popout' window. That will give you the window object of the parent.
So if on your main page you have a global variable test
var test = 'Hello';
It can be accessed from the child window using
window.opener.test
Related
I am using window.open to open a new window which will send some message to the parent window using window.opener.postMessage.
This child window URL is arbitrary. I mean there is a textbox where the users can give the URL and it will be opened using window.open.
Although the user is suspected to use the URLs that are supported, it is also possible that some random URL will be used. In this case, I don't want to child window to make any changes to the parent window, especially to the parent location.
How can I avoid this issue? I've tried to use noreferrer,noopener; however, that breaks entire cross-window communication altogether, which is not desired.
First I would like to say that I've been programming JavaScript for about 3 months now and also that I'm not very concerned with solving this problem by the standards or best practices. My main concern is learning to use the DOM. I don't want to use any jQuery because I'm not familiar with it.
I'm trying to make a non-profesional "login" function on my page, using JavaScript and the DOM. To begin with I was using "login" screen that would be displayed "hidden" initially and then be displayed "block" when in use. This worked fine and looked really good when I added a darkened screen behind the "login" screen by adding less opacity (0.1 opacity) to the main part of the page that's beneath the "login screen".
This (the opacity) would return to normal when I closed the "login" screen. So you can see all the stuff is happening within the same page using the same DOM. OK, this is how I wanted it to work: you create a username then you your create a password. Boom, finished!
But here's the problem: after you create a username and password I want it to say "Hello (username here)" where the login link initially was. I could just use the DOM and insert the username into the HTML page, but when I submit the form that is the login function the page gets reloaded and the changes to the DOM become erased!
So now I can tell you about the solution I thought of: make the form (login page) be in a new window, so when the form is submitted (and the DOM is manipulated) the new window is reloaded and then subsequently closes leaving the changes to the main pages DOM intact. Only problem is I can't figure out how to do this. You could probably say that's a major problem hahaha.
So, can I manipulate the parent windows (i.e. the calling window) DOM from the new window?
In response to your answer: you can modify the caller window's DOM by using window.opener.document from the new window;
window.opener is a reference to the caller window (if any, otherwise null), but only if both windows are from the same domain).
NOTE: Is it a small webpage or you are going to do a lot of DOM manipulation on a web site/application via javascript? In the later case you should use a javascript library/framework (I recommend jQuery) in order to do the dirty job more easily.
A popup window can find the window that opened it using the opener variable.
If both the popup window and the original window originate from the same domain, then the popup window can indeed modify the HTML of the original window.
If the popup window and the original window contain content from a different domain, then they can't see the HTML of each other - due to the cross-origin protection that browsers put in place.
I have scenario like P is parent page and from that page one child page is being open using window.open(C) where C is child page. Now I have to navigate in same child window. Let's call that page as C1.
I found when I try to access one button of page P from page C1, it gave me not found.
My syntaxt is like (in page C1),
window.opener.document.getElementById('xyz');
Is there any way using which I can identify the page I am getting in window.opener is same page what I am looking for?
You ask:
Is there any way using which I can identify the page I am getting in window.opener is same page what I am looking for?
Just an idea: generate some random value before opening the new window and store it in the parent window, write this value to the new window and cross-reference.
Update:
You can share data between parent and child browser windows at some scenarios as shown below:
window.opener.functioname(arg1,arg2,..)
- to send data to the parent window from child window
winobj.functioname(arg1,arg2,..)
- to send data to the child window from parent window using the window handle got from window.open()
See for a lot more info on this page.
Good luck!
I am using FCKEditor on my parent page and child page opened from that editor only. So I have to have use window.opener.parent.my_function();
Thanks a lot to all who helped me.
My site opens up a popup window to an external site, but at some point, the popup window will redirect to my site again. Because of security reasons, I know I can't look at the popup window URL until it redirects to back to my site. What I did is kept checking every second to see whether I could access the url address, and once I could, (meaning the popup window was back on my site) I stored the Url info and closed the popup. This seems like a pretty bad way of doing it...
Is there any way to detect the window returning to my site?
If you have control over the linkback page for the popup then you can set up a special page just for this purpose. All you'd need to do would be to create a page with some javascript that runs to notify you that you have come full circle.
One property that popup windows have is the window.opener property which refers to the parent window that initially created the pop-up.
This should be a good place to start.
I am opening a paypal window from the parent with window.open(). After payment and redirecting back to my page (in the popup window), I would like to close the popup and update the parent window URL.
I found out this works over window.opener.location.
However the console shows
window.opener.location is null
after redirection because as the child window changes, the popup looses the information about the opener.
Well great. Now is there any way to get around this? Maybe adding a sort of "listener" to the parent who listens to the URL of the child?
window.opener is removed whenever you navigate to a different host (for security reasons), there is no way around it. The only option should be doing the payment in a frame if it is possible. The top document needs to stay on the same host.
First you can have a timer function in the parent windows to check whether the child window is opened or closed at particular time interval say 100ms or so. If it is closed then you can reload the parent window.
The issue with window.opener in IE is when you using localhost site and the internet site like paypal. Simply change location of your local host from Local Intranet to the Internet zone and the opener will not be null.