Copy text string on click

You can attach copy event to <span> element, use document.execCommand(“copy”) within event handler, set event.clipboardData to span .textContent with .setData() method of event.clipboardData const span = document.querySelector(“span”); span.onclick = function() { document.execCommand(“copy”); } span.addEventListener(“copy”, function(event) { event.preventDefault(); if (event.clipboardData) { event.clipboardData.setData(“text/plain”, span.textContent); console.log(event.clipboardData.getData(“text”)) } }); <span>text</span>

Android: how to select texts from webview

The above answers looks perfectly fine and it seems you’re missing something while selecting text. So you need to double check the code and find your overridden any TouchEvent of webview. i Tried below code it works fine… Function is private void emulateShiftHeld(WebView view) { try { KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, … Read more

Intercept paste event in Javascript

You can intercept the paste event by attaching an “onpaste” handler and get the pasted text by using “window.clipboardData.getData(‘Text’)” in IE or “event.clipboardData.getData(‘text/plain’)” in other browsers. For example: var myElement = document.getElementById(‘pasteElement’); myElement.onpaste = function(e) { var pastedText = undefined; if (window.clipboardData && window.clipboardData.getData) { // IE pastedText = window.clipboardData.getData(‘Text’); } else if (e.clipboardData && … Read more

How can I “intercept” Ctrl+C in a CLI application?

Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { /* my shutdown code here */ } }); This should be able to intercept the signal, but only as an intermediate step before the JVM completely shutdowns itself, so it may not be what you are looking after. You need to use a SignalHandler (sun.misc.SignalHandler) to intercept the … Read more