javascript changes based on the dtd????

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

    javascript changes based on the dtd????

    Hello all,

    I created a function which gets the position of the mouse. This works fine
    untill I insert a doctype declaration in the file. The properties
    'scrollLeft' and 'scrollTop' in IE will not change anymore. This means the
    javascript is changed based on the doctype?

    Is this a bug?
    Which functions and properties will change their behaviour in what doctype?
    Do I miss something?
    Is there a solution?


    btw in firefox all works as expected
    code:

    <!--
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "DTD/xhtml1-strict.dtd">
    -->
    <html>
    <head>
    <script type="text/javascript">

    function initPage(){
    // set onmouse move event handler to capture the mouse
    position
    document.onmous emove=getMouseP osition;

    // get object
    window.obj=docu ment.getElement ById('test');
    }

    function getMousePositio n(e){
    var x=(e &&
    e.pageX)?e.page X:event.x+docum ent.body.scroll Left;
    var y=(e &&
    e.pageY)?e.page Y:event.y+docum ent.body.scroll Top;

    window.obj.styl e.left=x+'px';
    window.obj.styl e.top=y+'px';

    document.getEle mentById('test' ).innerHTML="x= "+x+",y="+y+',< br
    />(scrollLeft='+ document.body.s crollLeft+',scr ollTop='+docume nt.body.scrollT op+')';

    }

    window.onload=i nitPage;
    </script>
    </head>
    <body>
    <div id="test"
    style="display: block;position: absolute;width: 200px;height:50 px;border:1px
    solid black;"></div>
    <div style="width:20 0%">
    <br /><br /><br /><br /><br /><br />
    <br /><br /><br /><br /><br /><br />
    <br /><br /><br /><br /><br /><br />
    </div>
    </body>
    </html>


  • Martin Honnen

    #2
    Re: javascript changes based on the dtd????



    somebody wrote:
    [color=blue]
    > I created a function which gets the position of the mouse. This works fine
    > untill I insert a doctype declaration in the file. The properties
    > 'scrollLeft' and 'scrollTop' in IE will not change anymore. This means the
    > javascript is changed based on the doctype?
    >
    > Is this a bug?
    > Which functions and properties will change their behaviour in what doctype?[/color]

    IE 6 has two rendering modes, one called quirks mode, one called strict
    mode (or called standards compliant mode), and the DOCTYPE declaration
    decides on the rendering mode.
    In strict mode the <html> element defines the canvas while in quirks
    mode the <body> element does so if you use document.body.s crollTop/Left
    in quirks mode in strict mode you need
    document.docume ntElement.scrol lTop/Left.

    You can check
    if (typeof document.compat Mode != 'undefined' &&
    document.compat Mode != 'BackCompat') {
    // use document.docume ntElement.scrol lTop/Left
    }
    else {
    // use document.body.s crollTop/Left
    }


    More details on the rendering mode are here:
    <http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dnie60/html/cssenhancements .asp>

    Note that Mozilla and Opera also switch rendering modes based on the
    DOCTYPE declaration, for Mozilla see
    <http://www.mozilla.org/docs/web-developer/faq.html>

    --

    Martin Honnen

    Comment

    • somebody

      #3
      Re: javascript changes based on the dtd????


      "Martin Honnen" <mahotrash@yaho o.de> schreef in bericht
      news:427e3e63$0 $10511$9b4e6d93 @newsread4.arco r-online.net...[color=blue]
      >
      >
      > somebody wrote:
      >[color=green]
      >> I created a function which gets the position of the mouse. This works
      >> fine untill I insert a doctype declaration in the file. The properties
      >> 'scrollLeft' and 'scrollTop' in IE will not change anymore. This means
      >> the javascript is changed based on the doctype?
      >>
      >> Is this a bug?
      >> Which functions and properties will change their behaviour in what
      >> doctype?[/color]
      >
      > IE 6 has two rendering modes, one called quirks mode, one called strict
      > mode (or called standards compliant mode), and the DOCTYPE declaration
      > decides on the rendering mode.
      > In strict mode the <html> element defines the canvas while in quirks mode
      > the <body> element does so if you use document.body.s crollTop/Left in
      > quirks mode in strict mode you need
      > document.docume ntElement.scrol lTop/Left.
      >
      > You can check
      > if (typeof document.compat Mode != 'undefined' &&
      > document.compat Mode != 'BackCompat') {
      > // use document.docume ntElement.scrol lTop/Left
      > }
      > else {
      > // use document.body.s crollTop/Left
      > }
      >
      >
      > More details on the rendering mode are here:
      > <http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dnie60/html/cssenhancements .asp>
      >
      > Note that Mozilla and Opera also switch rendering modes based on the
      > DOCTYPE declaration, for Mozilla see
      > <http://www.mozilla.org/docs/web-developer/faq.html>
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/[/color]



      Thanks, thanks, thanks ......(1000 times)


      Rob




      Comment

      • RobG

        #4
        Re: javascript changes based on the dtd????

        somebody wrote:[color=blue]
        > "Martin Honnen" <mahotrash@yaho o.de> schreef in bericht
        > news:427e3e63$0 $10511$9b4e6d93 @newsread4.arco r-online.net...
        >[color=green]
        >>
        >>somebody wrote:
        >>
        >>[color=darkred]
        >>>I created a function which gets the position of the mouse. This works
        >>>fine untill I insert a doctype declaration in the file. The properties
        >>>'scrollLef t' and 'scrollTop' in IE will not change anymore. This means
        >>>the javascript is changed based on the doctype?
        >>>
        >>>Is this a bug?
        >>>Which functions and properties will change their behaviour in what
        >>>doctype?[/color]
        >>
        >>IE 6 has two rendering modes, one called quirks mode, one called strict
        >>mode (or called standards compliant mode), and the DOCTYPE declaration
        >>decides on the rendering mode.
        >>In strict mode the <html> element defines the canvas while in quirks mode
        >>the <body> element does so if you use document.body.s crollTop/Left in
        >>quirks mode in strict mode you need
        >>document.docu mentElement.scr ollTop/Left.
        >>
        >>You can check
        >> if (typeof document.compat Mode != 'undefined' &&
        >> document.compat Mode != 'BackCompat') {
        >> // use document.docume ntElement.scrol lTop/Left
        >> }
        >> else {
        >> // use document.body.s crollTop/Left
        >> }
        >>
        >>
        >>More details on the rendering mode are here:
        >><http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dnie60/html/cssenhancements .asp>
        >>
        >>Note that Mozilla and Opera also switch rendering modes based on the
        >>DOCTYPE declaration, for Mozilla see
        >><http://www.mozilla.org/docs/web-developer/faq.html>
        >>
        >>--
        >>
        >>Martin Honnen
        >>http://JavaScript.FAQTs.com/[/color]
        >
        >
        >
        >
        > Thanks, thanks, thanks ......(1000 times)[/color]

        You may also want to check out this from the quirksmode site:

        <URL:http://www.quirksmode. org/viewport/compatibility.h tml>


        --
        Rob

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: javascript changes based on the dtd????

          somebody wrote:
          [color=blue]
          > [...]
          > I created a function which gets the position of the mouse. This works fine
          > untill I insert a doctype declaration in the file. The properties
          > 'scrollLeft' and 'scrollTop' in IE will not change anymore. This means the
          > javascript is changed based on the doctype?[/color]

          No, but the DOM probably is.
          [color=blue]
          > Is this a bug?[/color]

          No.
          [color=blue]
          > Which functions and properties will change their behaviour in what
          > doctype?[/color]

          Undefined.
          [color=blue]
          > Do I miss something?[/color]

          Yes. There is the core language, and there is the DOM.
          [color=blue]
          > Is there a solution?[/color]

          Declare the DOCTYPE properly and avoid proprietary references.
          [color=blue]
          > btw in firefox all works as expected[/color]

          Shit happens.
          [color=blue]
          > code:
          >
          > <!--
          > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          > "http://www.w3.org/TR/html4/loose.dtd">
          > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          > "http://www.w3.org/TR/html4/strict.dtd">
          > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
          > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
          > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          > "DTD/xhtml1-strict.dtd">
          > -->[/color]

          You may want to explain what this is supposed to do.
          [color=blue]
          > [...][/color]

          PointedEars

          Comment

          Working...