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.
Related
I am trying to detect whether the current page is already opened in a different tab or not.
I tried using window.open(), but I get as return the current window itself, not the supposedly other window of same address. It will always return true.
So say, if 'mysite.com' is already opened, when the user opens a new window with 'mysite.com', I shall detect that, focus the other window and close the current one.
Would love to hear any ideas, or whether this is possible. I'm trying to capture all links into a single tab.
You can use localStorage events to communicate between different tabs and therefore detect if a page is already opened. Check this answer: https://stackoverflow.com/a/14792159/60745
Even when you're only concerned with a tab in the same browser on the same machine, the problem with trying to accomplish this through pure javascript is that although you could set a cookie on each of your sites pages (window.onload) to record the user has initially visited your site, there's no safe way to ensure you remove this cookie when they leave.
Although you have the onunload & onbeforeunload events, these are not fired when you leave a site over a link, uses a browsers back button or closes the browser.
I am using an Iframe window to display the login form of another website. And what I want is the user should go to that particular site after logging in(even if logging in fails, any click on any link in that iframe should take the user to that site in the full window(parent window).
As long as the links (within the iFrame) are part of the other page, you can't "hijack" their target. You would have to have the means and ability to modify the target attribute of each link to point to _parent or use javascript to reference the window.parent.
Based on what you're saying (you're logging in to a different domain and the page is not part of your site) this wouldn't be possible without implementing some kind of proxy where you could modify the contents between page visits.
I'm building an app that involves authentication via third-party. To make the process not redirect the actual app I open a new window that then does the authentication and returns to main window after success.
This doesn't, however, go as well as planned. When the popup redirects to third-party and back, window.opener gets null. It's still possible to close the popup by window.close() but I also need to refresh the logged-in-area in the main window, like this:
window.opener.check_auth_status();
I really hope there is a way to fix this, e.g. binding a function to popup-close in the main window? Refreshing the whole page would be highly unnecessary.
One way is to set an interval to main window checking if the popup is closed, but this seems so fiddly.
You have a few options that may or may not work in the latest versions of the browsers due to security updates
1) check that the window is closed from the opener - not fiddly and actually the safest
2) give the opener a name
window.name="myMainWindow";
and in popup (script from SAME domain) - should normally not open a new window or change content
var handle = window.open("","myMainWindow");
handle.check_auth_status();
3) use an iFrame in the popup and when you want to access the opener, use top.opener
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.
Using javascript "window.close()" method after opening new window using "window.open", it serve the problem i.e. but it will ask a confirmation message to user whether he really wants to close the window or not... if user selects yes then the parent window will close and if not then he will remain on the same window and new window will not get open up..
So is there any way so that parent window will get closed without asking any confirmation message and new window will gets open up ?
No. It´s a security feature. You are trying to manipulate an application on another users machine.
If you put it in another context it becomes clear why it is as it is and why it should be that way: Would you like if your email client suddenly closed cause you read an email?
EDIT: What you can do is having the login window trigger a navigate event in it´s opener so the first page gets replaced by the billing info page. Then it can close itself.