473,418 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

onload event in mozilla...

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
Jul 23 '05 #1
4 4883
Pai wrote:
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
Jul 23 '05 #2
> 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:
to******************************@invalid.com
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 23 '05 #3
Pai wrote:
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()
{
Jul 23 '05 #4
Pai wrote:
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: <http://jibbering.com/faq/>
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:

<http://pointedears.de.vu/scripts/test/whatami>
} <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
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: steve | last post by:
Hi all I have this onLoad event it is working fine but I'm just queries is this the right ware to do it? <body onLoad="st_setkopcheta1(10,10,10,'stmenubottom','stmenu1','stsubmenu1'...
4
by: Dariusz | last post by:
I have a page which is a mixture of PHP and Javascript, it's not a PHP problem as it is only printing the Javascript I want out to the browser. When the page executes, in Internet Explorer the...
7
by: Tery Griffin | last post by:
Hi all, Iıve been away from Javascript for awhile and am rusty, but this is too simple not to work! Iım on a Mac, and usually use the Safari browser. I have a very basic web page in a frame. ...
6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
3
by: Disco-181 | last post by:
Hi, I have a script which isn't working in Mozilla based browser for some reason. I'm trying to run two functions from the body onload tag and it simply isn't happening. I have a cascading...
9
by: Sunny | last post by:
Hi, I have cr8ed a javascript function in the head section of a jsp page. <!-- function go(theURL) { alert(theURL); if (theURL!=null){
1
by: bjarthur | last post by:
i have (see below) what i think is a fairly simple algorithm, but yet it doesn't work. given a directory with consecutively numbered jpeg files (1.jpg, 2.jpg, 3.jpg...), it is designed to count...
2
by: Martin Honnen | last post by:
I was playing around with canvas support in recent Safari, Mozilla and Opera (only version 9 preview) but run into issues with Safari related to the very old DOM Level 0 Image object for preloading...
6
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.