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

Cookies and Windows

P: n/a
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.
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <25**************************@posting.google.com >,
du**********@setel.com enlightened us with...

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

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.