Re: Referencing windows by name? -- now a Working Opener and Callback
Robert Mark Bram wrote:
[color=blue]
> Howdy All!
>
> I finally worked this out. Thanks very much to DU, who I hope will excuse me
> for posting the sloppy html below - the only thing I want to show here is
> the valid EcmaScript required to do the job.
>
> This example involves two windows - a menu window and a content window.
> Clicking links from the menu window open their documents in the content
> window, loading only when appropriate. In turn, each content page has a link
> back to the menu window, again, only loading where appropriate.
>
> Any comments, criticisms or corrections welcome!
>
> Rob
> :)
>
> ==========
> menu.htm
> ==========
> <html><head>
> <script type="text/javascript">
>
> window.name = "menuWindow ";[/color]
I don't think this is needed; right now, I don't see this as necessary
nor recommendable. menu.htm can be referred as the opener all the time;
opener is a pointer, a window object reference while window.name is just
a string property of the window object only useful in conjunction with
the HTML 4 target attribute.
[color=blue]
> var contentWindow;
> var previousContent Url;
>
> // Menu window uses this function to open a content window.
> function openContentWind ow (contentUrl)
> {
> if (contentWindow == null ||
> contentWindow.c losed)
> {
> contentWindow = window.open (contentUrl, "contentWindow" );
> } // end if
> else if (previousConten tUrl != contentUrl)
> {
> contentWindow = window.open (contentUrl, "contentWindow" );
> contentWindow.f ocus();
> } // end else if
> else
> {
> contentWindow.f ocus();
> } // end else
>
> previousContent Url = contentUrl;
> } // end openContentWind ow function
> </script>
> </head><body>
> <h1>Menu:</h1>
> <p><a href="content1. htm"
> onClick="openCo ntentWindow(thi s.href); return false;">Content 1</a></p>
> <p><a href="content2. htm"
> onClick="openCo ntentWindow(thi s.href); return false;">Content 2</a></p>
> </body>
> </html>
>
>
> ==========
> content1.htm
> ==========
> <html><head>
> <script type="text/javascript" src="windowCode .js"></script>
> </head><body>
> <h1>Content 1</h1>
> <p><a href="menu.htm"
> onClick="showMe nuWindowFromCon tentWindow(this .href); return
> false;">Menu</a></p>
> </body></html>
>
> ==========
> content2.htm
> ==========
> <html><head>
> <script type="text/javascript" src="windowCode .js"></script>
> </head><body>
> <h1>Content 2</h1>
> <p><a href="menu.htm"
> onClick="showMe nuWindowFromCon tentWindow(this .href); return
> false;">Menu</a></p>
> </body></html>
>
>
> ==========
> windowCode.htm
> ==========
> function showMenuWindowF romContentWindo w (pageUrl)
> {
> // Either gain reference to a window nameed menuWindow
> // or open a blank window named menuWindow.
> menuWindow = window.open('', 'menuWindow');[/color]
Right here, I think you need to explain your logic a bit. Why would you
want to load the opener (menuWindow) into the content window? This does
not strike to me as natural, recommendable.. .
[color=blue]
>
> // If it is a blank window then its location will be blank
> // and should be reloaded.
> if (String (menuWindow.loc ation) != pageUrl)[/color]
This line above looks ok but for debugging purposes, it's preferable to use
if (String (menuWindow.loc ation.href) != pageUrl)
This way of coding is more reliable.
Also, the previous line just opened an empty, "about:blan k" document:
so, menuWindow.loca tion.href will always be different from the pageUrl.
I'm a bit confused on the purpose of your page. Why do you absolutely
need to use 3 windows (1 opener and 2 popups)?
[color=blue]
> {
> menuWindow.loca tion.replace (pageUrl);
> } // end if
> else
> {
> menuWindow.focu s();
> } // end else
> } // end openMenuWindow function
>
>[/color]
menuWindow should be declared outside that function as a global
variable: just var menuWindow
Finally, you can add these lines in your top part of your documents to
trigger standards compliance rendering mode in MSIE 6 for windows:
<!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</title>
DU
Robert Mark Bram wrote:
[color=blue]
> Howdy All!
>
> I finally worked this out. Thanks very much to DU, who I hope will excuse me
> for posting the sloppy html below - the only thing I want to show here is
> the valid EcmaScript required to do the job.
>
> This example involves two windows - a menu window and a content window.
> Clicking links from the menu window open their documents in the content
> window, loading only when appropriate. In turn, each content page has a link
> back to the menu window, again, only loading where appropriate.
>
> Any comments, criticisms or corrections welcome!
>
> Rob
> :)
>
> ==========
> menu.htm
> ==========
> <html><head>
> <script type="text/javascript">
>
> window.name = "menuWindow ";[/color]
I don't think this is needed; right now, I don't see this as necessary
nor recommendable. menu.htm can be referred as the opener all the time;
opener is a pointer, a window object reference while window.name is just
a string property of the window object only useful in conjunction with
the HTML 4 target attribute.
[color=blue]
> var contentWindow;
> var previousContent Url;
>
> // Menu window uses this function to open a content window.
> function openContentWind ow (contentUrl)
> {
> if (contentWindow == null ||
> contentWindow.c losed)
> {
> contentWindow = window.open (contentUrl, "contentWindow" );
> } // end if
> else if (previousConten tUrl != contentUrl)
> {
> contentWindow = window.open (contentUrl, "contentWindow" );
> contentWindow.f ocus();
> } // end else if
> else
> {
> contentWindow.f ocus();
> } // end else
>
> previousContent Url = contentUrl;
> } // end openContentWind ow function
> </script>
> </head><body>
> <h1>Menu:</h1>
> <p><a href="content1. htm"
> onClick="openCo ntentWindow(thi s.href); return false;">Content 1</a></p>
> <p><a href="content2. htm"
> onClick="openCo ntentWindow(thi s.href); return false;">Content 2</a></p>
> </body>
> </html>
>
>
> ==========
> content1.htm
> ==========
> <html><head>
> <script type="text/javascript" src="windowCode .js"></script>
> </head><body>
> <h1>Content 1</h1>
> <p><a href="menu.htm"
> onClick="showMe nuWindowFromCon tentWindow(this .href); return
> false;">Menu</a></p>
> </body></html>
>
> ==========
> content2.htm
> ==========
> <html><head>
> <script type="text/javascript" src="windowCode .js"></script>
> </head><body>
> <h1>Content 2</h1>
> <p><a href="menu.htm"
> onClick="showMe nuWindowFromCon tentWindow(this .href); return
> false;">Menu</a></p>
> </body></html>
>
>
> ==========
> windowCode.htm
> ==========
> function showMenuWindowF romContentWindo w (pageUrl)
> {
> // Either gain reference to a window nameed menuWindow
> // or open a blank window named menuWindow.
> menuWindow = window.open('', 'menuWindow');[/color]
Right here, I think you need to explain your logic a bit. Why would you
want to load the opener (menuWindow) into the content window? This does
not strike to me as natural, recommendable.. .
[color=blue]
>
> // If it is a blank window then its location will be blank
> // and should be reloaded.
> if (String (menuWindow.loc ation) != pageUrl)[/color]
This line above looks ok but for debugging purposes, it's preferable to use
if (String (menuWindow.loc ation.href) != pageUrl)
This way of coding is more reliable.
Also, the previous line just opened an empty, "about:blan k" document:
so, menuWindow.loca tion.href will always be different from the pageUrl.
I'm a bit confused on the purpose of your page. Why do you absolutely
need to use 3 windows (1 opener and 2 popups)?
[color=blue]
> {
> menuWindow.loca tion.replace (pageUrl);
> } // end if
> else
> {
> menuWindow.focu s();
> } // end else
> } // end openMenuWindow function
>
>[/color]
menuWindow should be declared outside that function as a global
variable: just var menuWindow
Finally, you can add these lines in your top part of your documents to
trigger standards compliance rendering mode in MSIE 6 for windows:
<!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</title>
DU
Comment