Forum Moderators: open

Message Too Old, No Replies

Use the same target window for several links

how to raise it to the top each time

         

scooch

10:30 am on Aug 29, 2002 (gmt 0)

10+ Year Member



I've got a page with four links on it that when clicked open a new window with a target=subpage attribute.

Say the user clicks on a link, gets that subpage, and then alt-tabs back to the original page, leaving the subpage open and hidden behind the original window.

The user clicks on a second link. The page loads in that already created window, but it doesn't come to the top. So the user thinks nothing happened. This happens to me all the time when surfing.

What onclick JS can I put in the 4 links so that the page named 'subpage' will raise to the top?

Or do I need to do the whole thing with JS, window.open's, and all?

Grumpus

11:02 am on Aug 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I forget exactly, I haven't done javascript for a while, but you need to do a "setFocus" (document.setFocus?) in the page's onload event. Go into the javascript docs and look into those terms and you'll have it.

G.

BlobFisk

12:02 pm on Aug 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use the onBlur event to close the window if you wanted. Not sure if this is exactly what you were looking for.

In the head write a small javascript function to close the window, and then in the <body> tag use onBlur="runMyFunction()". This will then close the child window if the focus is removed from it.

I wouldn't really recommend it though. If the user is on the child page, gets a new email, clicks on their mail client (thus removing focus from the child window), the window will close... leading to extreme confusion and annoyance on the users part!

scooch

12:29 pm on Aug 29, 2002 (gmt 0)

10+ Year Member



Thanks for the replies so far. Reading these replies, I realize that I neglected to mention an important point... the obvious answer is to put the javascript in the subwindow to call setfocus on itself. But I don't own the website in new subwindow that I'm opening. I have to do it from the parent window.

So I guess, what I'm really looking for is the real code that does this pseudocode:


<a href="www.othersite.com/new_window" target=subwindow onclick="if exists(new_window) then focus(new_window)">

Digging into my javascript docs now with the guidance so far, still hoping that someone has this right off the top of their heads. :)

Grumpus

2:03 pm on Aug 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could create an invisible frame. Create a frameset page on your own site which has one frame and load that remote page in the frame. The frameset page then gets your own header information, but all it actually displays is the contents of the framed page. With a little work, you could even make it so the javascipt would actually pass the the required frame URL to the frameset page so that you aren't stuck making a gazillion different frameset pages.

G.

RossWal

5:37 pm on Aug 29, 2002 (gmt 0)

10+ Year Member



Here's what I use. A word of caution though. In the past I got some errors that stated something about a 'security violation has occurred'. It had to do with one window manipulating another. This was on an intranet where we had control of the browsers. The error was on some ie4 desktops. An upgrade to ie5.5/6 fixed it, but I don't know whether to attribute it to browser version or custom settings.

Anyways, good luck.


function openWindowNav(url,name) {
popupWin = window.open(url,name, 'menubar=1,scrollbars=1,location=1,
toolbar=1,resizable=1,status=1,
width='+(screen.width * .8)+',height='+(screen.height * .7)+',left=40,top=40')
popupWin.focus()
}

Note that I split the 1st line in the function into 3 for posting. It surely won't run like that!

keyplyr

2:01 am on Aug 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Without all the hocus pocus, you could just use unique names for each target, thus they open new windows.

rewboss

6:33 am on Aug 30, 2002 (gmt 0)

10+ Year Member



If you are using the target attribute of an <a> tag, you can't reference the window with JavaScript, so you'd need to use JavaScript to open the window, as RossWal suggested.

However, the simplest and most effective solution is to put the following in the code that will be loaded into the new window:


<body onload="self.focus();">

Having pages load into one window instead of a new window every time has many definite advantages for the user.

keyplyr

9:13 am on Aug 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Well, I still don't see why JS is necessary (if I understand the problem correctly)

I have a similiar page that employs about a dozen pop-up (child) windows to present additional info to a resource. I use the same unique target name in the <a> tag for each of these and define their size according to the amount of content they contain.

If, as the poster suggests, I use alt/tab to return to the parent page and then click on another pop-up link, the new window will occupy the same place as the prior pop-up did, and will stay on top. The only possible problem I can see is that the size dimensions of the first pop-up will be inherited to the next pop-up since the first wasn't closed properly (this happens only once) and BTW, just how many users are closing child windows with alt/tab anyway - LOL

I am using IE6 in standards-compliant mode.

rewboss

7:17 pm on Aug 30, 2002 (gmt 0)

10+ Year Member



Not all browsers automatically bring the window to the top of the stack. I think Netscape is one of those that don't.