You cannot do this with JavaScript and I dare say you never will be able to.
If you need to do this for some kind of game element, for example, I recommend that you place a page-element under the mouse and prevent the page-element from moving outside of the bounds even if the mouse does.