onload event in mozilla...

P

Pai

hello there,

I am trying to rersize the window it works find in IE but doea not work with mozilla

window.attachEvent(onload,MWSOnLoad);
window.onload = function (MWSOnLoad)
{
alert('hello');
window.resizeTo(810,750);
top.outerWidth=810;
top.outerHeight=750;
}

<body marginwidth="0" marginheight="0" scroll="yes" onload="MWSOnLoad()">

could anybody guide me with this.

Thanks,
Srikanth pai
 
M

Mick White

Pai said:
hello there,

I am trying to rersize the window it works find in IE but doea not work with mozilla

window.attachEvent(onload,MWSOnLoad);
window.onload = function (MWSOnLoad)
{
alert('hello');
window.resizeTo(810,750);
top.outerWidth=810;
top.outerHeight=750;
}

<body marginwidth="0" marginheight="0" scroll="yes" onload="MWSOnLoad()">

could anybody guide me with this.

At first glance, you have duelling onloads , and I doubt if it would
work in IE, which knows nothing about top.outerWidth, And it's extremely
rude to change the user's window size.
Mick
 
G

Gernot Frisch

I am trying to rersize the window it works find in IE but doea not
work with mozilla

On Mozilla Firefox, you can set options to forbit JS to change the
window size... and I like it!

--
-Gernot

Post here, don't email. If you feel you have to mail, revert my
forename from:
(e-mail address removed)
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
K

Keith Bowes

Pai said:
hello there,

I am trying to rersize the window it works find in IE but doea not work with mozilla

window.attachEvent(onload,MWSOnLoad);
window.onload = function (MWSOnLoad)
{
alert('hello');
window.resizeTo(810,750);
top.outerWidth=810;
top.outerHeight=750;
}

I think you're doing it wrong. In your window.onload function, you're
sending MWSOnLoad as a parameter (not the name of the function).
Secondly, attachEvent is proprietary IE; the standard is addEventListener.

What you probably meant is:
window.attachEvent('onload', MWSOnLoad);

function MWSOnLoad()
{
 
T

Thomas 'PointedEars' Lahn

Pai said:
I am trying to rersize the window it works find in IE but doea not work with mozilla

Usenet postings, with few exceptions like source code and URIs, should not
exceed the 80th column to be easily readable without horizontal scrolling
(if even available). If your UA does not support automatic line-break (as
Google Groups) when posting, please break your lines manually (it's best to
break them before the 80th column, 72 or 76 is recommended to allow
quotation levels be marked by ">" or another character) or use a working UA
(as a newsreader program). Read the FAQ: said:
window.attachEvent(onload,MWSOnLoad);
window.onload = function (MWSOnLoad)
{
alert('hello');
window.resizeTo(810,750);
top.outerWidth=810;
top.outerHeight=750;
}

This cannot work. Firstly, (window.)onload is `null' by default. You tell
the UA to attach `MWSOnLoad' which evaluates to `undefined', as it was not
defined before, to `onload' which is `null'. Thus the first line is
semantically equal to

window.attachEvent(null, undefined);

What do you expect the UA to do then? If it does not yield a runtime error
(which is likely, see the FAQ) that statement does exactly _nothing_ useful
and you should simply omit it.

The correct syntax for window.attachEvent() is described in the MSDN Library
(I like Firefox's location bar ;-)):

,-<http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/attachevent.asp>
|
| [...]
| Syntax
|
| bSuccess = object.attachEvent(sEvent, fpNotify)
|
| Parameters
|
| sEvent Required. String that specifies any of the standard DHTML
| Events.
| fpNotify Required. Pointer that specifies the function to call when
| sEvent fires.

You see that the first parameter/argument must be a *string* which your code
clearly is not as there are no string delimiters. You also see that the
second argument must be a "function pointer", or correctly in JScript, a
Function object reference which your code is not as no function with that
identifier was defined. That's one error. The other one that contributes
to the first error is a mix of bad syntax (looks more like fantasy syntax)
and bad style:
window.onload = function (MWSOnLoad)
{

What you do here is to define an _anonymous_ function that therefore
cannot be referred to by identifier. Since `MWSOnLoad' is located
within parantheses, it is considered to be the identifier of the
anonymous function's arguments, _not_ the function's identifier. It
works anyway in IE since you assign to a proprietary event handler
property.

The script fails in Mozilla(/5.0, I assume) since window.attachEvent()
is part of the IE DOM and not defined in the Gecko DOM or other DOMs:

,-<ibid>
|
| There is no public standard that applies to this method.

But other HTML UAs, including Mozilla/4.0+, tend to support the proprietary
event handler properties, including "onload". So if you omit the first
line, it is likely to work. That does not mean that it must work. Besides
support for proprietary event handler properties, functionality depends on
the way the function was defined and the statements within the assigned
function. See below.
alert('hello');

What should that achieve other than irritate the user?
window.resizeTo(810,750);

That does not achieve full screen display as you might think. Instead it
irritates the user again because you manipulate his/her working environment
in an irresponsible way without asking for permission first. The size of
the browser window you try to manipulate here does not correspond in any
way with the size of the viewport and areas that correspond to it:

Display resolution != desktop size != browser window size != viewport size.
[psf 3.7]

("!=" means "not equal to" if you do not know this.)
top.outerWidth=810;
top.outerHeight=750;

This also relates to the irresponsible manipulation of the working area I
described above. But more important, you access objects and properties of
a proprierary DOM, not parts of the language. Thus it is likely this will
yield a script error if executed in host environments that does not provide
that DOM and its objects. So you should feature-test objects and properties
before you access them, no matter if you write to them or read from them:

<body marginwidth="0" marginheight="0" scroll="yes" onload="MWSOnLoad()">

"marginwidth", "marginheight" and "scroll" are proprietary attributes,
meaning that they are not defined in any public version of HTML and thus
both render such markup Invalid HTML and do not work in all recent UAs as
well as likely not to work in the future. Therefore you should omit those
attributes (especially scroll="yes" is nonsense as it is the default) and
replace them by standards compliant CSS formatting:

<body style="margin:0" onload="MWSOnLoad()">

But now you must decide what you want: Do you want *either*

A) a reference to an anonymous function to be assigned as event listener
to the proprietary "onload" event handler property? Then omit the
standards compliant "onload" attribute here and use

window.onload = function()
{
// original code goes here
}

Note that this will not work in hosts environment that does
not support anonymous functions; you may workaround that with
either

window.onload = function MWSOnLoad()
{
// original code goes here
}

(the function is given an identifier)

or

window.onload = new Function(
"// original code goes here;"
+ "// note that some characters must be escaped"
);

(a new Function object is created directly; useful if you do not
want closures)

Note that neither works if proprietary event handler properties are
not supported.

*or* do you want

B) to use the standards compliant intrinsic "onload" event handler
attribute and call a function named "MWSOnLoad" in the event listener?
Then leave the (corrected) HTML code as is and declare the function as

function (MWSOnLoad)
{
// original code goes here
}

*before* you call it (i.e. within a "script" element as child of the
"head" element).

Note that this does not work if the "onload" attribute is ignored
(I know no browser with script support that does this).
could anybody guide me with this.


HTH

PointedEars
 

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,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top