また、Rプログラム出力エリアをクリックした際に、文字列を自動全選択されるようにしました。
工夫した点は、ブラウザによって動作が異なる点です。
ChromeとSafariではクリックイベントで、IEとFireFoxとOperaではフォーカスイベントで動作するように分岐しています。
これで1回目のクリックで全選択、再クリックで選択解除になります。
HTMLのテキストエリア
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea onfocus="onoffSelect_focus(this);" onclick="onoffSelect_click(this);"></textarea> |
JavaScriptの関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onoffSelect_focus(obj){ | |
var userAgent = window.navigator.userAgent.toLowerCase(); | |
if(userAgent.indexOf("msie") > -1) { | |
obj.focus(); | |
obj.select(); | |
}else if(userAgent.indexOf("firefox") > -1) { | |
obj.focus(); | |
obj.select(); | |
}else if(userAgent.indexOf("opera") > -1) { | |
obj.focus(); | |
obj.select(); | |
} | |
} | |
function onoffSelect_click(obj){ | |
var userAgent = window.navigator.userAgent.toLowerCase(); | |
if(userAgent.indexOf("chrome") > -1) { | |
obj.focus(); | |
obj.select(); | |
}else if(userAgent.indexOf("safari") > -1) { | |
obj.focus(); | |
obj.select(); | |
} | |
} |