onselectstart() function on HTML
<pre><code>document.body.onselectstart = function() {
   return false;
}
</code></pre>

<p>I have this part of code in my <code>windows.onload = function start()</code>funtion. When I drag my mouse on top to down my context is not selecting. However If I drag my mouse from the bottom to top I can select whatever I want. Is there a way to prevent both dragging from top to bottom and reverse?</p>

<p>Full code below:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;

  &lt;/head&gt;
  &lt;body oncontextmenu="return false;"&gt;

    Value:&lt;br&gt; &lt;p id="Value"&gt; 0 &lt;/p&gt;

    &lt;p&gt;Click the ball to increase the value.&lt;/p&gt;

    &lt;input type="image" onmousedown="increase()" src="RedBall.png" id="demp" style="position:relative; left: 500px; top: 80px; width: 32px; height: 32px;" /&gt;


    &lt;script&gt;
      function increase() {
        var x = document.getElementById("Value").innerHTML;
        var increased = parseInt(x,10) + parseInt(1,10);
        document.getElementById("Value").innerHTML = increased;
      }

      function change(){
        var num = 0;
        window.setInterval(function(){
          var speedx= Math.floor((Math.random() * 11) - 5);
          var speedy= Math.floor((Math.random() * 11) - 5);
          document.getElementById("demp").style.left= parseInt(document.getElementById("demp").style.left, 10) + parseInt(speedx,10) +"px"; 
          document.getElementById("demp").style.top= parseInt(document.getElementById("demp").style.top, 10) + parseInt(speedy,10) +"px"; 
        }, 10)
      }
      window.onload = function start() {
        change();
        document.body.onselectstart = function() {
          return false;
        }
      }
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
</p>

<p><a href="https://output.jsbin.com/niyijuqaco" rel="nofollow">https://output.jsbin.com/niyijuqaco</a></p>

<p>You can also see the result on this site</p>