MikebEdwards
asked on
Only open a window if it doesnt already exist:
I have a page that on the body onload calls a funtcion to open a new window. The problem is that I only want this to happen when the window doesnt already exist. Hence the if !countentWindow. This doesnt work because the script doesnt no what contentWindow is. If i use a var contentWindow, then the if statement is always not true, and the eval is always called.
Any ideas?
function createContentWindow() {
winHeight = screen.availHeight;
maxX = screen.availWidth;
mainWidth = maxX - 260;
if (!contentWindow){
eval ("contentWindow = window.open('about:blank', 'contentWindow', 'height=" + winHeight + ", width=" + mainWidth + ", toolbar=no,location=no,sta tus=yes,me nubar=no,s crollbars= yes,resiza ble=yes'); ");
contentWindow.moveTo(260,0 );
contentWindow.resizeTo(mai nWidth, winHeight)
contentWindow.location.hre f="uservie w.asp";
}
}
Any ideas?
function createContentWindow() {
winHeight = screen.availHeight;
maxX = screen.availWidth;
mainWidth = maxX - 260;
if (!contentWindow){
eval ("contentWindow = window.open('about:blank',
contentWindow.moveTo(260,0
contentWindow.resizeTo(mai
contentWindow.location.hre
}
}
ASKER
That doesn't work because the
contentWindow.location.hre f="uservie w.htm";
Is never reached.
contentWindow.location.hre
Is never reached.
ASKER
This does seem to work though:
function createContentWindow() {
winHeight = screen.availHeight;
maxX = screen.availWidth;
mainWidth = maxX - 260;
contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',widt h='+mainWi dth+',tool bar=no,loc ation=no,s tatus=yes, menubar=no ,scrollbar s=yes,resi zable=yes' );
if(contentWindow.location. href!='abo ut:blank') {}
else {
contentWindow.location.hre f="uservie w.asp";
contentWindow.resizeTo(mai nWidth, winHeight)
contentWindow.moveTo(260,0 );
}
}
function createContentWindow() {
winHeight = screen.availHeight;
maxX = screen.availWidth;
mainWidth = maxX - 260;
contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',widt
if(contentWindow.location.
else {
contentWindow.location.hre
contentWindow.resizeTo(mai
contentWindow.moveTo(260,0
}
}
Does this work for you:
function createContentWindow() {
winHeight = screen.availHeight;
maxX = screen.availWidth;
mainWidth = maxX - 260;
contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',widt h='+mainWi dth+',tool bar=no,loc ation=no,s tatus=yes, menubar=no ,scrollbar s=yes,resi zable=yes' );
if(!contentWindow.myWindow ){
contentWindow.location.hre f="uservie w.htm";
contentWindow.resizeTo(mai nWidth, winHeight)
contentWindow.moveTo(260,0 );
contentWindow.myWindow=tru e;
}
}
function createContentWindow() {
winHeight = screen.availHeight;
maxX = screen.availWidth;
mainWidth = maxX - 260;
contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',widt
if(!contentWindow.myWindow
contentWindow.location.hre
contentWindow.resizeTo(mai
contentWindow.moveTo(260,0
contentWindow.myWindow=tru
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why did I get a grading B from you???
function createContentWindow() {
winHeight = screen.availHeight;
maxX = screen.availWidth;
mainWidth = maxX - 260;
contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',widt
if(!contentWindow.document
contentWindow.location.hre
contentWindow.resizeTo(mai
contentWindow.moveTo(260,0
}
}