onmousedownがじゃましてるから
addEventListenerの部分をこれでどうだろう
links[i].removeAttribute("onmousedown");
links[i].addEventListener('mousedown', function () {