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.
Related
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/
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.
I'm opening a popup as follows:
popup = window.open(url, "", "width=600,height=300,status=no,scrollbars=no,resizable=no");
popup.focus();
What I want to do is refresh the opener when the popup closes. Is this possible? Thanks
The following should do it (place it within <head>...</head>):
<script>
window.onunload=function(){
if(window.opener && !window.opener.closed)
window.opener.location.reload(true);
};
</script>
That's a problem if you can't place anything inside the popup. If you can't change the popup then you have limited choices. You can essentially set a session variable when the window first opens (in PHP or whatever your server language is), and have the page auto-refresh once it gains focus (assuming the popup gets focus on initial load). Have your server code detect the session variable, and if it's set, simply don't write the script to the head.
I am new to jQuery. I have a button on main page of my web application which creates a login pop. If user enters correct password then popup should be disappeared and the page which create that popup should go to welcome page of that user. I know how to disappear the popup if user enters correct password. How can I tell the explorer window which created that popup to go to the welcome page? Thanks in advance.
I believe with Javascript you can redirect the parent window with:
window.opener.location.href = <your url>;
And then simply close your popup:
window.close();
You don't need jQuery for this. Some simple JavaScript should do the trick.
//reload the parent window
//window.opener.location.reload();
//to change the parent window location
window.opener.location.href = "welcome.htm";
//close the current window
self.close();
I have a link which opens a page in a new tab in firefox.
<a target="_default" href='/portal.html' >
Go to Portal
</a>
However when I click this link again ,it refreshes the opened tab and doesn't set focus to it , so users have no way to know that tab is opened .
Is there any way by which I can grab the opened tab and set focus on subsequent clicks after opening it once Or any other workaround .
Thanks.
For getting the focus using a tabhandler name may help.. suppose we have
win = window.open("https://www.google.com", "test");
win.focus();
now every time the first line of above code runs the browser will first find the tab with the name test and reload it with the url https://www.google.com and in case it does not find a tab with the name test it will open a new one. On the run of the second line it will set the focus to the same tab loaded from the first line.
I had a similar problem in my project.
Luckily, whenever I needed to set focus on already opened tab, it also needed to be refreshed.
So I did it with the following trick, which first opened again tab with same href and target, got reference of that window back, closed it, and opened again with same parameters.
popup = window.open('/popup.html', '_popup')
popup.close()
popup = window.open('/popup.html', '_popup')
No.
Each tab normally runs in a separate process sandbox. It's just not possible.
At max you can try target="_blank".
You can probably use _blank and some JS code that closes a previously opened tab for the same URL using cookie tracking.
The page (that you are opening in the new tab) should be built in such a way that it writes out a cookie with some value (say current time in millis). It should also have some kind of a periodic poller that checks the value of this cookie and closes itself when the value is seen to be changed. the only way this value can change is when the same url is opened in another tab/popup.
Disclaimer: Not sure if browsers will allow window.close without it being user triggered though!