How can I get number of child windows for a browser - javascript

I have one icon (say open) in home page. When I click on this icon one child window will be open and the icon in that home page is also changed to 'close icon'. When close this popup window the icon should be same as previous icon (i.e. open icon) in home page. It's working fine when I stay on the same page.
But when redirecting from home page to next page the entire page gets reloaded. And the default image (open icon) is displaying even if the popup window is opened.
Now my requirement is:
At the time of page redirection the image should be loaded based upon the popup window. i.e. if popup window is open it should display the close icon otherwise it display open icon.
If page is refreshed or redirecting to another page the reference of the popup window is removed. then how can I get the reference of that popup window in a redirecting page.
How to count the number of child windows for a browser
EDIT:
I have tried the following solutions:
I set cookie at the time of opening a popup window and reset that cookie whenever I have closed that popup window. But the problem is, at the time of page redirection if I close the popup window the cookie is not reset to it's previous value, because the page is still in processing.
same problem with the session variable also
Please help me.

Set a cookie or a session variable when you open and close. This way you can remember the state of your popup window during new requests

When you go from one page to the next, you lose the reference to the pop-up window. But the pop-up window doesn't lose its reference to the main window. window.opener will always point to the window that opened it, even when there's a page change. Use this fact to reestablish communication between the windows after a navigation event. You might need to use an interval function to probe the main window, as I don't think you can listen for an event.

Related

How to stay on current window tab when the link opens in new tab

I want to stay on my current tab though. Is there anyway to not be redirected to that tab? I want the tab to open in the background.
When I do this command below, it opens a new tab and puts me into that url. I want to stay on my original page.
window.open('url/','_blank');
This is not something you have control over.
That functionality is determined by the browser and only the browser currently.

Closing a tab open in Chrome Extension before main window closes

I'm writing a Chrome Extension that opens an external (detached) window that is meant to be open for the rest of the session.
I'd like to get an event when the main window (with many tabs) is closing so that I close my tab before the main window. Otherwise, the tab will remain open and the user needs to close it manually. Thus, Chrome will remember it as the next time Chrome will open it instead of the other tabs that were in the main window. Obviously, this is a bad user experience.
The background script doesn't get any event when the main window closes.
Any idea how I could get this?

Chrome Extension : Retain modal window when page refreshes

In my chrome extension, I am using content script on a particular site. When a particular button is pressed, the page refreshes with new updates. Is there any way to show a Modal window or Popup, from the time the button is clicked till the page refreshes.
Modal window or popup: no
But you can use a chrome notification. It will show a customizable window which you can remember its id and take it down when the page refreshes. I do this for a popular extension i develop.

How can I open a pop-up window without it being blocked?

I haven't found a single answer able to tell me what's the right way to open a popup.
Times have changed, and popups have been mostly replaced with fancybox-like boxes. However, there are still times when popups are needed.
For those cases, I don't want my popup to be blocked by the browsers.
What's the right way to open a popup without it being blocked? Even if it opens a new tab in the browser. I just want my popup to be open, and have control of it from the parent or vice versa.
Popup blockers will block any popup, unless it is opened because of an user action.
If the user clicks on a link, and a popup is opened in the click listener of that link, the popup blocker knows the user want to open something and will not (or should not) block the popup.
What you cannot do:
open a popup when the page is opened or closed
open a popup after a certain interval
open a popup after something asynchronous happens
What you can do:
open a popup in the on click listener
using target="_blank" in a anchor tag
You can access both windows with JavaScript variables:
if you use window.open, the parent can have a reference to the popup by assigning the result of window.open to a variable. Check out this article at W3Schools.
If the popup needs to have access to the window who has opened it, you can use window.opener. Check out this question.
try this, it works for me
$('#myButton').click(function () {
var redirectWindow = window.open('http://google.com', '_blank');
redirectWindow.location;
});
Js fiddle for this is here https://jsfiddle.net/safeeronline/70kdacL4/2/
if you want to open new tab after ajax call see this fiddle http://jsfiddle.net/safeeronline/70kdacL4/1/

How to close all the child pages on LogOut

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.

Categories