An event handler for the select event on the window.
window.onselect = funcRef;
funcRef is a function.<html>
<head>
<title>onselect test</title>
<style type="text/css">
.text1 { border: 2px solid red; }
</style>
<script type="text/javascript">
window.onselect = selectText;
function selectText()
{
alert("select event detected!");
}
</script>
</head>
<body>
<textarea class="text1" cols="30" rows="3">
Highlight some of this text
with the mouse pointer
to fire the onselect event.
</textarea>
</body>
</html>
The select event only fires when text inside a text input or textarea is selected. The event is fired after the text has been selected.
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'onselect' in that specification. | Living Standard |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | Yes | Yes | ? | ? | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | Yes | Yes | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onselect