View Full Version : OK, I should know this ... but, unfortunately, I don't
Haybails
03-05-2002, 12:42 PM
Hey Folks~
Crazy ol' Haybails back to bother you with a question which I should know the answer too ... but, simply can't get the old grey matter to respond.
Here's the scenario:
Three pages. Page 1 and 2 are regular pages with links which open page 3 as a small "pop-up" window. I have the links on page 1 and 2 coded as such:
<a href="#" onmouseover="this.style.color='#FF0000';window.status='Meet the STAFF!';return true;" onmouseout="this.style.color='#FFFF00';window.status='';return true;" onclick="window.open('Contributors.asp','Staff','width=500,height=300,location=0,menubar=0,resizable=0,scroll bars=0,status=0,titlebar=0,toolbar=0,screenX=100,left=100,screenY=30,top=60,');">STAFF</a>
So, here's the problem. I click on the link on page 1 and page 3 correctly opens in it's little "pop-up" window. I can still see, of course, page 1 behind the page 3 in it's little "pop-up" window. Now, I bring Page 1 back to to the top of my "z-stack" and follow a different link to page 2. So now I have page 2 maximized with a little "pop-up" window of page 3 BENEATH and out of view. So, now I click on the link to page 3 (from page 2)
.................
How do I bring the little "pop-up" window of page 3 back to the top of my "z-stack"?
Dr. Web
03-05-2002, 01:18 PM
try adding a window.focus() event. that should bring it up.
Haybails
03-05-2002, 03:01 PM
Remember ... this is "Ol' Haybails" you're corresponding with.
Not only would I imagine myself buying you a round of your favorite beverage ...
But,
I'd also appreciate it very much.
Haybails
03-08-2002, 10:41 AM
I'm sorry "Dr. Webb" ... could I beg a slightly more indepth explaination. I'd appreciate it very much.
Dr. Web
03-08-2002, 12:40 PM
Sorry about that hay.... I hadn't checked this thread in a couple of days....
to have any window on top, youd put the window.focus() command in. So for instance, if you want a pop up to appear on top when it finished loading, you would put this in the pop up:
<body onLoad="window.focus();">
now, if your linking to popups from pop ups.... well this could get confusing for visitors. I am not sure if your springing up new content in an existing popup, or if your just pointing to the existing content in an existing popup.
You could put this in each page:
<script language=javascript>
function lookAtMe(){
window.focus()
}
</script>
and then when you hit a link, you can call the function in the pop up, and it will be on top.
Let me forewarn you of a few things. You have a base page that spawns these pop ups. So lets assume I am your visitor, and I click on a link that spawns popup1. At this point I should have all the info I need, and I will close the pop up. This defeats some of your navigation.
but lets say I click on a link in popup 1 and get pop up 2. Okay, so then I close #1, and look at number 2. Does this ruin things?
Also, you mentioned popup 3 being spawned from popup2. Hmmmnn.... this is getting messy. Personally I think one pop up at a time per page is the max. I am a seasoned surfer, and I have no qualms about pop ups if used sparingly and effectively. However, multiple pop ups used for navigation would complicate things, and I would probably get confused instead of get information.
Finally, a major caveat of trying to bring a existing popup to the 'top' is when it has been closed. Basically saying, how does the browser bring popup3 to the top when the surfer has closed it already. It will error out, unless you have provided code to make sure that the pop up exists, and if not to respawn it.
I only mean this as a useability comment, but you might consider another way of displaying information rather than 1 base page, and three pop ups. Id be willing to help you out and introduce ideas that might work.
Good luck!
_mrkite
03-11-2002, 12:07 AM
Haybails -
When you open a window with JavaScript, a new JS window object is generated and returned by the window.open() function. If you don't assign it to a variable, you lose your primary 'handle' on the new window, the JS object which represents it. Clean up that HTML! Sample:
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="JavaScript">
var sFeatures = 'status=0,resizable';
function doWin(URL,handle,wid,hgt,lt,tp,features,IEheightAdj) {
if (wid && hgt) {
var sW = (screen) ? screen.availWidth : 600;
var sH = (screen) ? screen.availHeight : 400;
if (IEheightAdj && document.all)
hgt = (hgt.indexOf('%') != -1) ?
(((parseInt(hgt)*.01)*sH) * IEheightAdj).toString() : (hgt * IEheightAdj).toString();
var w = (window.outerWidth) ? 'outerWidth=' : 'width=';
var h = (window.outerHeight) ? 'outerHeight=' : 'height=';
w = (wid.indexOf('%') != -1) ? w + ((parseInt(wid)*.01)*sW) : w + wid;
h = (hgt.indexOf('%') != -1) ? h + ((parseInt(hgt)*.01)*sH) : h + hgt;
var l = (lt.indexOf('%') != -1) ? 'left=' + ((parseInt(lt)*.01)*sW) : 'left=' + lt;
var t = (tp.indexOf('%') != -1) ? 'top=' + ((parseInt(tp)*.01)*sH) : 'top=' + tp;
window[handle] = open(URL,handle,w + ',' + h + ',' + l + ',' + t + ',' + features);
} else if (window[handle] && !window[handle].closed) window[handle] = open(URL,handle);
setTimeout('if(window["'+handle+'"]&&!window["'+handle+'"].closed)window["'+handle+'"].focus()',100);
}
function grabWin(handle) {
if (window[handle] && !window[handle].closed) window[handle].focus();
}
function shutWin(handle) {
if (window[handle] && !window[handle].closed) window[handle].close();
}
</script>
</head>
<body>
<a href="#"
onclick="doWin('Contributors.asp','Staff','80%','80%','10%','10%',sFeatures,'.93');return false;">open<br>STAFF</a><br><br>
<a href="javascript:void doWin('http://www.htmlforums.com','Staff')">
load<br>STAFF<br>(new url)</a><br><br>
<a href="javascript:void grabWin('Staff')">focus<br>STAFF<br>window</a><br><br>
<a href="javascript:void shutWin('Staff')">close<br>STAFF<br>window</a>
</body>
</html>
The 'IEheightAdj' is a bit of a hack to compensate for the difficulty in setting the outer dimensions of a window (Netscape got that right) - experiment if you use any of this. To answer your Q:
if (window_variable && !window_variable.closed)
window_variable.focus();
...where window_variable is a global variable (that you returned the aforementioned object to).
Sorry for the long-windedness.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.