Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 window.open 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...

C#
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 = window.open(Target,'_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) {
                       clearInterval(intervalId);
                       if (newWindowsArray.length > 0) {
                           for (i = 0; i < newWindowsArray.length; i++) {
                               removeItem(newWindowsArray, Target);
                               break;
                           }
                       }
                   }
               }, 10);

           }
       }
       function removeItem(array, item) {
           if (array.length > 0) {
               for (var i in array) {
                   if (array[i] == item) {
                       array.splice(i, 1);
                       break;
                   }
               }
           }
       }
       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
Updated 18-Mar-13 22:00pm
v2
Comments
Prasad Khandekar 19-Mar-13 15:37pm    
Hello,

You will have to maintain an array of child window handle (returned via window.open 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900