Click here to Skip to main content
11,714,345 members (81,747 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
1.I have two links, when ever user clicks on a link ,child window opens and loads the cross domain url.
If the user click it again,I want to notify user or set focus to the already opened window. How can I achieve this. I tried setting a name to the window in function call, But whenever I try to access it, it return 'ACCESS IS DENIED'

I tried using an array to store already opened windows urls and if the user requests the same url, an alert message is shown. But I want to set focus to the already opened window, the user is requesting.

2.How to close all the child windows when parent window is closed?

3.How can I trigger logout button click when user closes the main window/browser?

for the first question I tried...

newWindowsArray = new Array();
       var scrwid = $(window).width(); var scrht = $(window).height(); var winhgt = scrht - 140; var winwdth = scrwid - 20;
       function OpenWindow(Target, Name) {
           if (checkItem(newWindowsArray, Target)) {
               openedWindow =,'_blank', 'width=' + winwdth + ',height=' + winhgt + ',status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1,screenX=0,screenY=170,top=170,left=10');
               newWindowsArray[newWindowsArray.length] = Target;
               var intervalId = setInterval(function () {
                   if (openedWindow.closed) {
                       if (newWindowsArray.length > 0) {
                           for (i = 0; i < newWindowsArray.length; i++) {
                               removeItem(newWindowsArray, Target);
               }, 10);
       function removeItem(array, item) {
           if (array.length > 0) {
               for (var i in array) {
                   if (array[i] == item) {
                       array.splice(i, 1);
       function checkItem(array, item) {
           if (array.length > 0) {
               for (var i in array) {
                   if (array[i] == item) {
                       alert('window already opened!');//I want to set focus to the opened window.
                       return false;
               return true;
           else {
               return true;

for 3rd question:

window.onbeforeunload:function(){triggered button click}//not working.....

same with unload function.

any suggestion is appreciated..................
Posted 17-Mar-13 22:34pm
Edited 18-Mar-13 22:00pm
Prasad Khandekar at 19-Mar-13 15:37pm

You will have to maintain an array of child window handle (returned via call) Then in parent windows unload event you need to call close for each of the handle. You can write handler for window objects onBeforeUnload event and make an Ajax call to logout the user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 420
1 Maciej Los 229
2 Richard MacCutchan 220
3 OriginalGriff 170
4 F-ES Sitecore 140
0 Sergey Alexandrovich Kryukov 545
1 CHill60 375
2 Maciej Los 324
3 Richard MacCutchan 310
4 OriginalGriff 260

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100