onload event in mozilla...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pai

    #1

    onload event in mozilla...

    hello there,

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

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

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

    could anybody guide me with this.

    Thanks,
    Srikanth pai
  • Mick White

    #2
    Re: onload event in mozilla...

    Pai wrote:
    [color=blue]
    > hello there,
    >
    > I am trying to rersize the window it works find in IE but doea not work with mozilla
    >
    > window.attachEv ent(onload,MWSO nLoad);
    > window.onload = function (MWSOnLoad)
    > {
    > alert('hello');
    > window.resizeTo (810,750);
    > top.outerWidth= 810;
    > top.outerHeight =750;
    > }
    >
    > <body marginwidth="0" marginheight="0 " scroll="yes" onload="MWSOnLo ad()">
    >
    > could anybody guide me with this.
    >[/color]

    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

    Comment

    • Gernot Frisch

      #3
      Re: onload event in mozilla...

      > 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:
      tonreG.Frisch.a t.Dream-D-Sign.de@invalid .com
      _______________ _______________ __________
      Looking for a good game? Do it yourself!
      GLBasic - you can do
      GLBasic is a programming language that supports multiple platforms like e.g. iPhone



      Comment

      • Keith Bowes

        #4
        Re: onload event in mozilla...

        Pai wrote:[color=blue]
        > hello there,
        >
        > I am trying to rersize the window it works find in IE but doea not work with mozilla
        >
        > window.attachEv ent(onload,MWSO nLoad);
        > window.onload = function (MWSOnLoad)
        > {
        > alert('hello');
        > window.resizeTo (810,750);
        > top.outerWidth= 810;
        > top.outerHeight =750;
        > }
        >[/color]

        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 addEventListene r.

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

        function MWSOnLoad()
        {

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: onload event in mozilla...

          Pai wrote:
          [color=blue]
          > I am trying to rersize the window it works find in IE but doea not work with mozilla[/color]

          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/>
          [color=blue]
          > window.attachEv ent(onload,MWSO nLoad);
          > window.onload = function (MWSOnLoad)
          > {
          > alert('hello');
          > window.resizeTo (810,750);
          > top.outerWidth= 810;
          > top.outerHeight =750;
          > }[/color]

          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.attachEv ent(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.attachEv ent() 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.attachEv ent(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:
          [color=blue]
          > window.onload = function (MWSOnLoad)
          > {[/color]

          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.attachEv ent()
          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.
          [color=blue]
          > alert('hello');[/color]

          What should that achieve other than irritate the user?
          [color=blue]
          > window.resizeTo (810,750);[/color]

          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.)
          [color=blue]
          > top.outerWidth= 810;
          > top.outerHeight =750;[/color]

          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>
          [color=blue]
          > }[/color]
          [color=blue]
          > <body marginwidth="0" marginheight="0 " scroll="yes" onload="MWSOnLo ad()">[/color]

          "marginwidt h", "marginheig ht" 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="MWSOnLo ad()">

          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).
          [color=blue]
          > could anybody guide me with this.[/color]


          HTH

          PointedEars

          Comment

          Working...