Re: Adding CSS units to an old JS Script

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

    Re: Adding CSS units to an old JS Script

    rfr a écrit :
    I am a cut-n-paste javascript user and trying to update this script.

    I have tried adding +"px" to the barW and barH lines. But that didnt get it
    to work.
    This below works for me in Firefox,
    you can put this script in the head of your page(s)

    Code:
    <script language="JavaScript1.2" type="text/javascript">
    
    // Based on watermark script by Paul Anderson, CNET Builder.com.
    // All rights reserved.
    
    // and then ?
    // it was no more working ... so ... the rights ...
    
    var markW = 90, // pixels wide
    markH = 40, // pixels high
    markX = 99, // percent right
    markY = 99, // percent down
    markRefresh = 50; // milliseconds
    
    var posX, posY, wMark, navDOM, markID;
    
    function setVals() {
    var barW = 0; // scrollbar compensation for PC Nav
    var barH = 0;
    if (navDOM)
    {
    if (document.height innerHeight) barW = 20;
    if (document.width innerWidth) barH = 20;
    }
    else
    {
    innerWidth = document.body.clientWidth;
    innerHeight = document.body.clientHeight;
    }
    posX = ((innerWidth - markW)-barW) * (markX/100);
    posY = ((innerHeight - markH)-barH) * (markY/100);
    }
    
    function wRefresh() {
    wMark.left = posX + (navDOM?pageXOffset:document.body.scrollLeft) +'px';
    wMark.top = posY + (navDOM?pageYOffset:document.body.scrollTop) + 'px';
    }
    
    function markMe() {
    // set common object reference
    wMark = document.all ? document.all['waterMark'].style :
    document.getElementById?
    document.getElementById('waterMark').style :
    document.waterMark;
    navDOM = window.innerHeight; // Nav DOM flag
    wMark.width = markW;
    wMark.height = markH;
    setVals();
    window.onresize=setVals;
    markID = setInterval ("wRefresh()",markRefresh);
    }
    
    window.onload=markMe; // safety for Mac IE4.5
    
    </script>

    This script works with an associated div somewhere (preferably at end)
    in the body of the page :

    Code:
    <div id="waterMark" style="position:absolute">
    <a href="#" onClick="window.scrollTo(0,0)">
    top
    </a>
    </div>

    --
    sm
  • rfr

    #2
    Re: Adding CSS units to an old JS Script

    Thank you.

    That does work in FireFox, Opera and Netscape. But it does not work in MSIE
    7.0.

    I have no idea why it doesnt work in MSIE 7.0

    And since MSIE is such a large part of the visitor audience, it has to work
    there too.

    "SAM" <stephanemoriau x.NoAdmin@wanad oo.fr.invalidwr ote in message
    news:48655f3c$0 $923$ba4acef3@n ews.orange.fr.. .
    rfr a écrit :
    >I am a cut-n-paste javascript user and trying to update this script.
    >>
    >I have tried adding +"px" to the barW and barH lines. But that didnt get
    >it to work.
    >
    This bellow works for me in Firefox,
    you can put this script in the head of your page(s)
    >
    Code:
    <script language="JavaScript1.2" type="text/javascript">
    >
    // Based on watermark script by Paul Anderson, CNET Builder.com.
    // All rights reserved.
    >
    // and then ?
    // it was no more working ... so ... the rights ...
    >
    var markW = 90, // pixels wide
        markH = 40, // pixels high
        markX = 99, // percent right
        markY = 99, // percent down
        markRefresh = 50; // milliseconds
    >
    var posX, posY, wMark, navDOM, markID;
    >
    function setVals() {
     var barW = 0; // scrollbar compensation for PC Nav
     var barH = 0;
    if (navDOM)
       {
       if (document.height innerHeight) barW = 20;
       if (document.width innerWidth) barH = 20;
       }
    else
       {
        innerWidth = document.body.clientWidth;
        innerHeight = document.body.clientHeight;
        }
    posX = ((innerWidth - markW)-barW) * (markX/100);
    posY = ((innerHeight - markH)-barH) * (markY/100);
    }
    >
    function wRefresh() {
    wMark.left = posX + (navDOM?pageXOffset:document.body.scrollLeft) +'px';
    wMark.top = posY + (navDOM?pageYOffset:document.body.scrollTop) + 'px';
    }
    >
    function markMe() {
    // set common object reference
    wMark = document.all ? document.all['waterMark'].style :
            document.getElementById?
                document.getElementById('waterMark').style :
            document.waterMark;
    navDOM = window.innerHeight; // Nav DOM flag
    wMark.width = markW;
    wMark.height = markH;
    setVals();
    window.onresize=setVals;
    markID = setInterval ("wRefresh()",markRefresh);
    }
    >
    window.onload=markMe; // safety for Mac IE4.5
    >
    </script>
    >
    >
    This script works with an associated div somewhere (preferably at end) in
    the body of the page :
    >
    Code:
    <div id="waterMark" style="position:absolute">
    <a href="#" onClick="window.scrollTo(0,0)">
      top
      </a>
    </div>
    >
    >
    --
    sm

    Comment

    • rfr

      #3
      Re: Adding CSS units to an old JS Script

      What changes to I need to make to this script to get it to also work in
      MSIE?

      "rfr" <rfrohrer@iw.ne twrote in message
      news:3v-dnamuKN4d9_jVnZ 2dnUVZ_judnZ2d@ prairiewave.com ...
      Thank you.
      >
      That does work in FireFox, Opera and Netscape. But it does not work in
      MSIE 7.0.
      >
      I have no idea why it doesnt work in MSIE 7.0
      >
      And since MSIE is such a large part of the visitor audience, it has to
      work there too.
      >
      "SAM" <stephanemoriau x.NoAdmin@wanad oo.fr.invalidwr ote in message
      news:48655f3c$0 $923$ba4acef3@n ews.orange.fr.. .

      Comment

      • SAM

        #4
        Re: Adding CSS units to an old JS Script

        rfr a écrit :
        What changes to I need to make to this script to get it to also work in
        MSIE?
        That would have to (IE4 ?)

        Here you are (tested IE6, Fx2, Safari3)
        Doesn't work with my IE Mac if the div marker has no border :



        Code:
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
        <html>
        <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>down marker</title>
        <script language="JavaScript1.2" type="text/javascript">
        
        // Based on watermark script by Paul Anderson, CNET Builder.com.
        // All rights reserved.
        
        // all the script is modified so ... the rights !!!
        
        // variable for test :
        n= 0;
        
        // fixing some values :
        var markW = 90, // pixels wide
        markH = 40, // pixels high
        markX = 99, // percent right
        markY = 99, // percent down
        markRefresh = 200; // milliseconds
        
        // some needed variables :
        var posX, posY, wMark, navDOM, markID;
        
        function setVals() {
        var barW = 0; // scrollbar compensation for PC Nav
        var barH = 0;
        if (navDOM)
        {
        if (document.height innerHeight) barW = 20;
        if (document.width innerWidth) barH = 20;
        }
        else
        {
        /*@cc_on var innerHeight, innerWidth; @*/
        innerWidth = !document.documentElement.clientWidth?
        document.body.clientWidth :
        document.documentElement.clientWidth;
        innerHeight = !document.documentElement.clientHeight?
        document.body.clientHeight :
        document.documentElement.clientHeight;
        }
        posX = ((innerWidth - markW)-barW) * (markX/100);
        posY = ((innerHeight - markH)-barH) * (markY/100);
        }
        
        function wRefresh() {
        wMark.left = +posX + (navDOM? pageXOffset :
        !document.documentElement.scrollLeft?
        document.body.scrollLeft :
        document.documentElement.scrollLeft) + 'px';
        wMark.top = +posY + (navDOM? pageYOffset :
        !document.documentElement.scrollTop?
        document.body.scrollTop :
        document.documentElement.scrollTop) + 'px';
        // these 2 lines for test
        n++;
        window.status = 'refresh #'+n;
        }
        
        function markMe() {
        // set common object reference
        wMark = (document.all && !document.getElementById)?
        document.all['waterMark'].style :
        document.getElementById?
        document.getElementById('waterMark').style :
        document.waterMark;
        navDOM = window.innerHeight; // Nav DOM flag
        wMark.width = markW + 'px';
        wMark.height = markH + 'px';
        setVals();
        window.onresize=setVals;
        markID = setInterval ("wRefresh()",markRefresh);
        }
        
        window.onload=markMe; // safety for Mac IE4.5
        
        </script>
        </head>
        <body>
        <DIV id="waterMark" style="position:absolute;border:1px solid">
        <a href="#" onClick="window.scrollTo(0,0);return false;">
        top signal
        </a>
        </DIV>
        <p style="border:1px solid;height:1500px;width:2000px">
        <a href="javascript:clearInterval(markID)">stop refreshing</a>
        </p>
        </body>
        </html>


        --
        sm

        Comment

        • SAM

          #5
          Re: Adding CSS units to an old JS Script

          SAM a écrit :
          >
          Here you are (tested IE6, Fx2, Safari3)
          Doesn't work with my IE Mac if the div marker has no border :
          And now compatible NC 4.7 !



          Code:
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">
          <html lang="fr">
          <head>
          <meta http-equiv="content-type" content="text/html; charset=utf-8">
          <title>down marker</title>
          <script language="JavaScript1.2" type="text/javascript">
          
          // Based on watermark script by Paul Anderson, CNET Builder.com.
          // All rights reserved.
          
          // all the script is modified so ... the rights ... p-) !!!
          // tested Mac OS X 10.4 : IE.5, Fx.2, Safari.3, Opera.9, iCab.3
          // tested Win XP SP2 : IE.6, NC.4.7
          
          // variable for test and to remove after try :
          n= 0;
          
          // fixing some values :
          var markW = 90, // pixels wide
          markH = 40, // pixels hight
          markX = 99, // percent right
          markY = 99, // percent down
          markRefresh = 200; // milliseconds
          
          // some needed variables :
          var posX, posY, wMark, navDOM, markID;
          
          function setVals() {
          var barW = 0; // scrollbar compensation
          var barH = 0; // scrollbar compensation
          if (navDOM)
          {
          if (document.height innerHeight) barW = 20;
          if (document.width innerWidth) barH = 20;
          }
          else  // for IE
          {
          /*@cc_on var innerHeight, innerWidth; @*/
          innerWidth = !document.documentElement.clientWidth?
          document.body.clientWidth :  // old IE and IE Mac
          document.documentElement.clientWidth;
          innerHeight = !document.documentElement.clientHeight?
          document.body.clientHeight :  // old IE and IE Mac
          document.documentElement.clientHeight;
          }
          posX = Math.floor(((innerWidth - markW)-barW) * (markX/100));
          posY = Math.floor(((innerHeight - markH)-barH) * (markY/100));
          }
          
          function wRefresh() {
          wMark.left = +posX + (navDOM? pageXOffset :
          !document.documentElement.scrollLeft?
          document.body.scrollLeft :
          document.documentElement.scrollLeft) +
          (!document.getElementById? '' : 'px');
          wMark.top = +posY + (navDOM? pageYOffset :
          !document.documentElement.scrollTop?
          document.body.scrollTop :
          document.documentElement.scrollTop) +
          (!document.getElementById? '' : 'px');
          // those 2 lines for test (to remove after try)
          n++;
          window.status = 'refresh #'+n;
          }
          
          function markMe() {
          // set common object reference
          wMark = (!document.getElementById && document.all)?
          document.all['waterMark'].style :
          document.getElementById?
          document.getElementById('waterMark').style :
          document.layers ?
          document.layers['waterMark'] :
          document.waterMark;
          navDOM = window.innerHeight; // Nav DOM flag
          // next line to remove after test
          alert(navDOM);
          wMark.width = markW + 'px';
          wMark.height = markH + 'px';
          setVals();
          window.onresize=setVals;
          markID = setInterval ("wRefresh()",markRefresh);
          }
          
          window.onload=markMe; // safety for Mac IE4.5
          
          </script>
          </head>
          <body>
          <div id="waterMark" style="position:absolute;border:1px solid">
          <a href="#" onClick="window.scrollTo(0,0);return false;">
          top signal
          </a>
          </div>
          <p style="height:1500px;width:1500px/* not used by NC*/">
          <a href="javascript:clearInterval(markID)">stop refreshing</a><br>
          <img src="#" width=1500 height=1500 alt="for NC to get scrollbars">
          </p>
          </body>
          </html>

          --
          sm

          Comment

          Working...