Robert Mark Bram wrote:
[color=blue]
> Hi Thomas.
>
> Your advice is pretty much what I originally tried. Here is a test scenario
> for that. My problem is that on each alert, the 'placed' window property is
> undefined!
>
> I am getting really frustrated here. Any advice would be most welcome!
>
> Rob
> :)
>[/color]
Your code has several problems, some are logical ones.
[color=blue]
> ============
> menu.htm
>
> ============
> <html><head>
> <script language="JavaScript" type="text/javascript"
> src="windowCode.js"></script>[/color]
If you want your code to work as best as possible in all compliant
browsers, then use a doctype declaration (preferably with a full url -
system id -, strict DTD) and validate your files. Here, language is
deprecated and invalid. type is both backward and forward-compatible, so
you can't be wrong .
[color=blue]
> </head>[/color]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Title goes here and is mandatory</title>
<script type="text/javascript" src="windowCode.js"></script>
</head>
<body>[color=blue]
> <p>Menu:</p>
> <p><a href="content1.htm"
> onClick="openContentWindow(this.href); return false;">Content 1</a></p>
> <p><a href="content2.htm"
> onClick="openContentWindow(this.href); return false;">Content 2</a></p>
> </body>
> </html>
>
>
> ============
> content1.htm
>
> ============
> <html><head>
> <script language="JavaScript" type="text/javascript"
> src="windowCode.js"></script>
> </head><body>
> <p>Content 1</p>
> <p><a href="menu.htm"
> onClick="openMenuWindow(this.href); return false;">Menu</a></p>
> </body></html>
>
> ============
> content2.htm
>
> ============
> <html><head>
> <script language="JavaScript" type="text/javascript"
> src="windowCode.js"></script>
> </head><body>
> <p>Content 2</p>
> <p><a href="menu.htm"
> onClick="openMenuWindow(this.href); return false;">Menu</a></p>
> </body></html>
>
>
> ============
> windowCode.js
>
> ============
> // Menu window uses this function to open a content window.
> function openContentWindow (pageUrl)
> {
> var win = null;[/color]
Your window object reference (win) is a local variable, not a global
variable. This has decisive importance in the way your script functions
and window object references can work interactively and efficiently.
[color=blue]
>
>
> alert ("window.contentWindow = " + window.contentWindow);
>[/color]
Your original post had contentWindow defined as a global variable and a
window object reference to a secondary window. Here, in this post, you
don't define it that way. So, it's already impossible to test, verify
your code. Best is to upload all these files in a site and then give an
url so that we can test, even debug the webpage application.
One other thing. If contentWindow is a window object reference, then
window.contentWindow is circular and unneedlessly redundant, auto-circular.
[color=blue]
> if (window.contentWindow &&
> !window.contentWindow.closed)
> {
> win = window.contentWindow;[/color]
I would drop entirely resorting to this local variable (win) to store a
global reference: it's counter-intuitive and not needed.
[color=blue]
> if (String(win.location) != pageUrl)
> {
> win.location.replace (pageUrl);
> } // end if
> } // end if
> else
> {
> win = window.open (pageUrl, "contentWindow");[/color]
Bad coding practice. You should always give distinct, unique, intuitive
and meaningful identifiers. Here, the window.name and the window object
reference identifier is the same. So this makes debugging more difficult
for reviewers or yourself later. Even when using application like a
javascript debugger, this makes the untangling of code unneedlessly more
difficult.
[color=blue]
> window.contentWindow = win;[/color]
This looks tortuous at best.
[color=blue]
> } // end else
> win.menuWindow = self;
> win.focus();[/color]
focus() calls should be done only if the targeted window has effectively
lost focus, otherwise this is a poor usage of user's system resources.
[color=blue]
> } // end openContentWindow function
>
>
>
>
> // Content windows use this function to open a menu window.
> function openMenuWindow (pageUrl)//(pageUrl, pageName, w, h, scroll, pos)
> {
> window.name="contentWindow";
>
> var win = null;
>
> alert ("self.menuWindow = " + self.menuWindow);
>
> if (window.menuWindow &&
> !window.menuWindow.closed)
> {
> win = window.menuWindow;
> if (String(win.menuWindow) != pageUrl)
> {
> win.location.replace (pageUrl);
> } // end if
> } // end if
> else
> {
> win = newMenuWindow (pageUrl);
> window.menuWindow = win;[/color]
The previous 2 lines up there are illogical, at best, redundant.
Compacted, it ends up as:
menuWindow = newMenuWindow(pageUrl);
where menuWindow is a local variable in your newMenuWindow function and
on the left side is a global variable. It's really confusing.
[color=blue]
> } // end else
>
> win.contentWindow = self;
> win.focus();
> } // end openMenuWindow function
>
>
> function newMenuWindow (pageUrl)
> {
> var pageName = 'menuWindow';
> var w = '800';
> var h = '450';
> var scroll = 'no';
> var pos = 'center';[/color]
pos is never used in your code.
[color=blue]
>
> var LeftPosition=(screen.width)?(screen.width-w)/2:100;
> var TopPosition=(screen.height)?(screen.height-h)/2:100;
>[/color]
Your code ignores space taken by os-dependent semi-permanent
applications. Explorer bar, NS/Mozilla sidebar, MS-magnify, MS-Office
quick launch bar, winbar, windows taskbar, etc.. are just examples of
applications re-defining the workarea for applications where a new
window can be positioned. The correct way to center a new window is to
consider the available screen dimensions for applications (referred as
workspace or workarea for applications in documentations).
[color=blue]
> var settings=
> 'width='+w+
> ',height='+h+
> ',top='+TopPosition+
> ',left='+LeftPosition+
> ',scrollbars='+scroll+
>
> ',location=no,directories=no,status=no,menubar=no, toolbar=no,resizable=no';
>[/color]
You're willing to turn off window resizability for a window which will
have a minimum of 800x450 dimensions. This can not promote usability.
You're also willing to turn off scrollbars if needed, that is if content
overflows your own requested window dimensions: this is
counter-usability and anti-userfriendly. Your code does not take into
consideration default font-size on the user's browser and studies show
that this is an important usability factor when browsing.
You're also willing to turn off status bar on a 800x450 window. Status
bar reports unbiased reliable notifications on connections, download,
SSL icon, security warnings, download progress, etc.. Why would you need
to remove the status bar?
[color=blue]
> var menuWindow = window.open (pageUrl, pageName, settings);
> return menuWindow;
> } // end openContentWindow function
>
>[/color]
var menuWindowObjectReference;
function newMenuWindow (pageUrl)
{
var windowWidth, windowHeight, windowLeft, windowTop;
if(typeof window.screenX == "number" && typeof window.innerWidth ==
"number")
{
windowWidth = window.innerWidth * .68;
windowHeight = window.innerHeight * .68;
windowLeft = window.screenX + window.innerWidth * .16;
windowTop = window.screenY + window.innerHeight * .16;
}
else if(typeof screen.availWidth == "number")
{
windowWidth = screen.availWidth * .68;
windowHeight = screen.availHeight * .5;
windowLeft = screen.availWidth * .16;
windowTop = screen.availHeight * .16;
}
else
{
windowWidth = 500;
windowHeight = 250;
windowLeft = 60;
windowTop = 40;
};
menuWindowObjectReference = window.open(pageUrl, "menuWindowName",
"left=" + windowLeft + ",top=" + windowTop + ",width=" + windowWidth +
",height=" + windowHeight + ",resizable,scrollbars,status");
}
I'm sure your problem is solvable. Can you upload all your files into a
website? I would look at it.
DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html