Firefox では問題ないようですが、Chrome と Internet Explorer ではまだテキストを選択できます。これを回避する方法はありますか? コードは別の質問から取られたものです(現在は見つかりません)ので、古くなっている可能性がありますか?
// Prevent selection
function disableSelection(target) {
if (typeof target.onselectstart != "undefined") // Internet Explorer route
target.onselectstart = function() { return false }
else if (typeof target.style.MozUserSelect != "undefined") // Firefox route
target.style.MozUserSelect = "none"
else // All other routes (for example, Opera)
target.onmousedown = function() { return false }
}
コードで次のように使用されます。
disableSelection(document.getElementById("gBar"));