Cookies and Windows

D

Duane

Hi ... here is my situation: I am building an application that is
driven by a main menu. When the user chooses an option from the main
menu that spawns a new window (or module). From that(or any) module
window there is a menu where the user can choose to go to or switch to
any other module. So ... lets say that the main menu has 4 options.
The user chooses option 1 which will open a new window (replacing the
main menu). On that new window there is a menu where the user can
choose another module (which would spawn that module's window) .. and
so forth.

The problem is this: Let's say the user has all 4 modules open and
then chooses from module1 to switch to module2....well that spawns a
new window instead of just giving module2 focus. I have solved a big
portion of this using cookies to let me know if the window is already
open...however, when the user chooses a module window that is already
open then I am having trouble giving that window focus.

Pseudo-code is like this and included in an external .js file that is
loaded by each new page:

if (getCookie(pageID) == "")
{
alert(pageID + ' not open .. will now open');
setCookie(pageID,'1','','','','');
if (pageID=='firstone')
Page1=window.open(page,'','fullscreen');
else if (pageID=='secondone')
Page2=window.open(page,'','fullscreen');
else if (pageID=='thirdone')
Page3=window.open(page,'','fullscreen');
}
else
{
alert(pageID + ' already open .. giving focus');
if (pageID=='firstone')
Page1.focus();
else if (pageID=='secondone')
Page2.focus();
else if (pageID=='thirdone')
Page3.focus();
}

Now this works until it runs into a page that is already loaded and
then tells me that "Page1 is null or not an object". I understand why
this is happening but am not sure how to make the new window objects
accessable to the other windows.

Any help would be greatly appreciated.
 
K

kaeli

The problem is this: Let's say the user has all 4 modules open and
then chooses from module1 to switch to module2....well that spawns a
new window instead of just giving module2 focus. I have solved a big
portion of this using cookies to let me know if the window is already
open...however, when the user chooses a module window that is already
open then I am having trouble giving that window focus.

You'd be better off giving the windows handles and checking for those.

This is mine for a help menu.
If the window is open, gives it focus and loads the help screen from an
array that is populated elsewhere in the script. Modify it for your
needs.
Tested for NN6+/IE5+. I can't guarantee it works in any other browser.

<script language="javascript" type="text/javascript">
var h_window = null;

function openHelp(screenName)
{
if (!h_window || h_window == null || typeof h_window == "undefined" ||
h_window.closed || !h_window.document)
h_window = window.open("","Help","height=200,width=
200,scrollbars=yes,resizable=yes");
var doc = h_window.document;
doc.open();
doc.writeln("<html><head><title>Help</title>");
doc.writeln("<link rel='stylesheet' type='text/css'
href='myStylesheet.css'>");
doc.writeln("</head><body>");
doc.writeln(h_array[screenName]);
doc.writeln("</body></html>");
doc.close();
h_window.focus();
return;
}
</script>

--
--
~kaeli~
She was engaged to a boyfriend with a wooden leg but broke
it off.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top