Click here to Skip to main content
11,630,144 members (80,801 online)
Rate this: bad
good
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 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...

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 17-Mar-13 22:34pm
PBGuy1.8K
Edited 18-Mar-13 22:00pm
v2
Comments
Prasad Khandekar at 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)

  Print Answers RSS


Advertise | Privacy | Mobile
Web03 | 2.8.150723.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