"annon" <annon@no.spam.com> writes:
[color=blue]
> I've noticed that some problems come up frequently that are of importance in
> writing web pages, because they're pretty fundamental points.[/color]
Yes, we have a FAQ for that :)
[color=blue]
> For general reference, here are some collected solutions.[/color]
Here are some comments
[color=blue]
> 1. Opens a new Window at maximum size:[/color]
First suggestion: Reconsider!
Opening new windows is not as safe as it once were, and new popup
blockers appear all the time. For a commerical site, dependency on
Javascript should be avoided.
At least, make it clear that a new, full screen window will appear
before the user clicks the button/link.
Second, the solution proposed doesn't open a new window at maximum
size. It moves and resizes the current window. Don't ever do that.
It's just rude. It will also fail in, e.g., my browser (Opera in MDI mode).
[color=blue]
> window.moveTo(0,0,screenX=0,screenY=0)[/color]
The assignments to screenX and screenY serve no purpose. Actually, the
last two arguments serve no purpose in any browser I know of. Just
make this:
window.moveTo(0,0);
No reason to leave out the final semicolon either.
[color=blue]
> window.resizeTo(screen.availWidth+2,screen.availHe ight+6)[/color]
Magic constants are a danger sign. Why +2 and +6? Which browser and
operating system are these constants meant form? Just go for
availWidth and availHeight with no modification. That's what they are
there for.
And again: Resizing user's browser without perission is rude.
[color=blue]
> 2. Defeats Frames (including Hotmail frames):
>
> if (window != top)
> top.location.href = location.href[/color]
Yes, this is the generic method. I don't like the formatting, though
(yes, I'm a pedant :)
if (window != top) {
top.location.href = location.href;
}
[color=blue]
> 3. Fixes a CSS Bug in Netscape Navigator:[/color]
Which bug? Which version of NN?
[color=blue]
> if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion)
> == 4)) {[/color]
Ah, Netscape 4. Does this work with both 4.04 and 4.80?
....
So this reloads the page if it is resized.
[color=blue]
> 4. Preloads images:
>
> if (document.images)[/color]
Why test for document.images, when all you use is window.Image?
[color=blue]
> 5. Opens a new Window with all window "furniture":
>
> function openNewWin(url)
> {
> var atts =
> 'menubar=yes,toolbar=yes,location=yes,status=yes,s crollbars=yes,resizable=ye
> s,directories=yes,menubar=1,toolbar=1,location=1,s tatus=1,scrollbars=1,resiz
> able=1,directories=1';
> var newWindow = open (url,'_blank',atts);
> newWindow.focus ()
> }
>
> - and is called in a HTML document (as shown in the examples below) by using
> the syntax openNewWin(index.html) or openNewWin(this.href)[/color]
openNewWin("index.html")
The reason for using this, and not just the equivalent
window.open(url,"_blank")
(or a link with target="_blank", which even works without Javascript)
has been omitted. However, when you want to set the size of the window,
and therefore include the third argument, you will need to add these.
Btw, which browser required the value to be "1" instead of "yes"?
Add standard disclaimer about opening new windows.
[color=blue]
> 6. Opens a new Window in maximum size (no window "furniture"):
>
> function openMaxWin(url)
> {
> var atts =
> 'menubar=no,toolbar=no,location=no,status=yes,scro llbars=yes,resizable=yes,m
> enubar=0,toolbar=0,location=0,status=1,scrollbars= 1,resizable=1';
> var newWindow = open (url,'_blank',atts);
> newWindow.focus ()
> }[/color]
No need to add the "=0" and "=no" declarations. That is the default when the
third argument is present. All non-present values are set to off.
[color=blue]
> 7. Opens a small pop-up type Window:
>
> function openPopWin(url)
> {
> var atts =
> 'top=0,left=0,menubar=no,toolbar=no,location=no,st atus=no,scrollbars=no,resi
> zable=no,screenX=0,screenY=0,menubar=0,toolbar=0,l ocation=0,status=0,scrollb
> ars=0,resizable=0,width=200,height=250';
> var newWindow = open (url,'_blank',atts);
> newWindow.focus ()
> }[/color]
Always, always make your popups resizable. If the content fit, the
users are not likely to use it anyway, and for some reason the content
doesn't fit the window, resizeability is essential (or scrollbars of
course).
Positioning the window at top=0,left=0 feels a little odd. I would expect
a popup to happen near the window I use.
[color=blue]
> 8. Opens a new Window in fullscreen:[/color]
See comments to solution 1.
[color=blue]
> function fullscreen(url)
> {
> w = screen.availWidth-10;
> h = screen.availHeight-20;[/color]
Magic numbers. Do they correspond to the border width of your
browser's windows on your operating system?
[color=blue]
> 9. A link to another page of your site, in a form that will work even with a
> browser which does not have Javascript enabled:[/color]
Amen! Always do this!
[color=blue]
> <a href="filename.htm" target="_blank"
> onClick="window.open(this.href,'','menubar=no,tool bar=no,location=no,status=
> yes,scrollbars=yes,resizable=yes');return false;">Click here</a>[/color]
(Beware of your usenet client, it breaks lines where they should not
be broken.)
You can even change the second argument of the call to window.open to
"this.target".
[color=blue]
> 10. Returns the date the page was last updated:[/color]
<URL:http://jibbering.com/faq/#FAQ4_30>
[color=blue]
> 11. Ways to call a function in a HTML page:
>
>
> Or to link to an <a name="abc"></a> style link on the same page:
> <a href="filename.htm#abc" onClick="window.location.reload()">Click here for
> #abc link</a><br>[/color]
Why reload the page first?
[color=blue]
> (c) To automatically load a set of standard scripts from an external .js
> file located in the subfolder "/scripts", put this in the page HEAD, ie
> before </head>:
>
> <script language=JavaScript src="scripts/filename.js"
> type=text/javascript></script>[/color]
The type attribute value must be quoted, since it contains the "/"
character, i.e.,
type="text/javascript"
There are four non-alphanumeric characters that are allowed in
un-quoted attribute values. If you can't remember them, always quote
your attribute values (See HTML 4.01 specification, section 3.2.2 for
a reminder, or do as I do: forget and quote everything.:)
You can safely omit the language attribute. It is deprecated and serves
no purpose when the (required) type attribute is present.
[color=blue]
> (d) To print the result from a javascript function in the BODY of a page
> (formatted by a CSS style "class" function), add the following in the <BODY>
> of the HTML document:
>
> document.write("<font class='classname'>" + functionName() + "</font>");[/color]
Don't use the font tag. It's deprecated and obsolete. Especially when
you *are* using CSS. Use <span> instead. That is the generic inline
element, which has no visible effect by itself.
Also worth noticing: if this code is contained in a script element of an
HTML page, the "</" will, according to the HTML specification, end the
script element right there. Browsers don't follow the specification, but
there is no need to live dangerously.
Change "</font>" to "<\/font>".
In summary, I'd say that most of this advice is sound, although with too
much weight on opening windows, which is something that should generally
be avoided.
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
Opening JS Windows <URL:http://www.infimum.dk/HTML/JSwindows.html>
'Faith without judgement merely degrades the spirit divine.'