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!');
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..................