By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Simple problem

P: n/a
I have web page that contains two links.
link "a" and link "b". When I click on "a" a small window should pop
up. when I click on "b" another small window should pop up. So what you
should see now is the base window which contains links "a" and "b" and
two small pop-up windows "a" and "b". Now I can make the script to pop
up "a" and "b" but the problem is that they're not shown at the same
time.

Any suggestions????

Sep 3 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ni**********@webinfo.fi wrote:
I have web page that contains two links.
.... and a really vague subject link.
link "a" and link "b". When I click on "a" a small window should pop
up.
*Shudder*
when I click on "b" another small window should pop up.
Double shudder.

Popup windows are a bad idea >99% of the time. The solution is almost
certainly to stop using popups.
So what you should see now is the base window which contains links "a"
and "b" and two small pop-up windows "a" and "b". Now I can make the
script to pop up "a" and "b" but the problem is that they're not shown at
the same time. Any suggestions????


Send your main window to the back so it doesn't cover up either of the
popups.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 3 '05 #2

P: n/a

<ni**********@webinfo.fi> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have web page that contains two links.
link "a" and link "b". When I click on "a" a small window should pop
up. when I click on "b" another small window should pop up. So what you
should see now is the base window which contains links "a" and "b" and
two small pop-up windows "a" and "b". Now I can make the script to pop
up "a" and "b" but the problem is that they're not shown at the same
time.


There's not much here to go by (some code would be nice) but the problem
sounds like one of focus.

When a window is given focus it's brought to the top of the stack. So this
seems like what's happening to you (each step indicates a change in focus):

1) Main window has focus. You click on "A".

2) The "A" popup window appears and is given focus (brought the top).

3) You click on "B" which gives the main window focus again. The main
window is brought to the top (probably sending the "A" window behind it).

4) The "B" popup window appears and is given focus (brought the top).

So, in this case you're left with current focus on the "B" window and a
window stack of "B" on top of Main and Main on top of "A"

Essentially to fix this the process of opening either popup window should
check to see if the other exists and give it focus at some point probably
giving the other popup focus first then returning it to the current popup).

You could do this when the popups are opened or, if the popups are
cooperative on each of their "window.onFocus()" events (when a popup gets
focus it should give the other focus for an instant to bring it up to the
top).

Take a look at the reference for the Window object - specifically the
Windows.focus() method.

Post back if you're still having problems and I'll work up some sample
script.

Hope this helps,

Jim Davis
Sep 4 '05 #3

P: n/a
Okay thanks for you help. This is what I'm using:
function AAA(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "',
'toolbar=0,scrollbars=1,location=0,statusbar=0,men ubar=0,resizable=1,width=548,height=482');");
}

function BBB(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "',
'toolbar=0,scrollbars=1,location=0,statusbar=0,men ubar=0,resizable=1,width=280,height=210');");
}
what should I add here to make it work as you told??

Thanks again -- Nizze

Sep 5 '05 #4

P: n/a
JRS: In article <11**********************@g43g2000cwa.googlegroups .com>
, dated Sat, 3 Sep 2005 16:07:36, seen in news:comp.lang.javascript,
ni**********@webinfo.fi posted :
I have web page that contains two links.
link "a" and link "b". When I click on "a" a small window should pop
up. when I click on "b" another small window should pop up. So what you
should see now is the base window which contains links "a" and "b" and
two small pop-up windows "a" and "b". Now I can make the script to pop
up "a" and "b" but the problem is that they're not shown at the same
time.


I suspect that you may be using window.open with a constant second
parameter, so that each "new" window uses the same window as is already
popped.

I use, for example,

var Wndw = window.open("", "X"+ +new Date(),
"height=" + (14*Obj.Cnt+42) + ",width=" + (8*BoxX+20) +
",resizable,scrollbars")

Pop-ups are often criticised; but there's nothing wrong with generating
them as a result of explicit user request.

I'm still wondering how best to calculate height and width so that that
window fits round <pre> text comprising Obj.Cnt rows and BoxX columns.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 5 '05 #5

P: n/a
<ni**********@webinfo.fi> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Okay thanks for you help. This is what I'm using:


I may be wrong here (I'm working from memory and I've got a lousy memory).

The first problem is that you need to know the names of your windows or have
a reference to them to do this - so the AAA function would need to know the
name or have a reference of the BBB window and vice versa. Since you're
window names are dynamically generated this will be harder than it would be
with static name - but it's not so difficult with references. Also you
should really get into the habit of using the var keyword for local
variables... you'll thank me later.

For now I'm just going to write a variable in the main page global scope
called "AAAWindowName" and "BBBWindowName". But there are definately many,
many other ways to do this.

Are you actually using the generated name "page" + id? If not there's
really no need to eval this just to set the variable. I'm going to assume
that you're NOT and can just use the window name. For this purpose I'll
call it "page" + id just because it feels odd to have an numeric identifier
for this. Consider having your function return a reference to the new
window and use that instead.

There's no real need, from the code you have here, to have two functions -
the only difference is the width and height and they could be passed as
arguments to a generic "open window" funciton.

But let's start simply. Function AAA might look like this:

function AAA(URL) {

// First Generate the Window Name
var WinName = "page" + new Date().getTime();

// Open the window, assign a reference to it to a local variable
var CurWindow = window.open(URL, WinName, ' ... window stuff...);

// Add a reference to the window the main page.
AAAWindow = CurWindow;

// Now adjust focus, if needed, of the other window
// First we must check to see if the other variable has actually
been defined
if ( typeof BBBWindow == 'object' ) {
// Give the BBBWindow focus via the stored reference
BBBWindow.focus();
};
// Now give THIS window focus to make sure it's still on top
CurWindow.focus();

// Now return a reference to the window for use in the rest of the
application:
// If you need the name instead return "WinName" and use it.
return CurWindow;

};

That's good but let's make it more generic.

From what you've described I'm just not seeing the need to generate names of
the windows... let's, for a moment say, you don't need to. Let's also say
that you want to make this general enough to use with any number of windows
(I won't get into the interface issues there... but they definitely exist).
So, instead of single "AAAWindow" and "BBBWindow" variables we'll create a
hash map of window references.

// Create a new global object (our hash map)
PopupGroup = new Object();

// Create a generic createPopup function
function createPopup(Name, URL, height, width) {

// Open the window, assign a reference to it to a local variable
var CurWindow = window.open(URL, Name, ' ... window stuff - include
height and width...);

// Add a reference to the window to the hash map.
// You could also do this in the line above but I'm being methodical
here
PopupGroup[Name] = CurWindow;

// Now bring ALL popups in the group to the front
for ( Popup in PopupGroup ) {
PopupGroup[Popup].focus();
};

// Now give the newly created popup focus to make sure it's still on
top
CurWindow.focus();

// Now return a reference to the popup for use in the rest of the
application:
return CurWindow;

};

To open your two windows here you might call the function like this:

createPopup("AAA", URL, 482, 548);
createPopup("BBB", URL, 210, 280);

To then access them in the rest of the application you could use:

PopupGroup["AAA"] or PopupGroup["BBB"]

For example:

PopupGroup["AAA"].document.write("Hello!");

Personally I always lean towards organizing things like this... it makes
life a lot simpler (I think).

Hope this helps,

Jim Davis

Sep 5 '05 #6

P: n/a
Thanks a lot every body.. especially Jim!

Sep 9 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.