Copy to clipboard with jQuery/js in Chrome

You can use either document.execCommand(‘copy’) or addEventListener(‘copy’), or a combination of both. 1. copy selection on custom event If you want to trigger a copy on some other event than ctrl-c or right click copy, you use document.execCommand(‘copy’). It’ll copy what’s currently selected. Like this, on mouseup for example: elem.onmouseup = function(){ document.execCommand(‘copy’); } EDIT: … Read more

How can I copy to the clipboard the output of a cell in a Jupyter notebook?

Jupyter notebook runs in browser so you can use some javascript to select and copy cells to clipboard. After some trial and error I came up with this bookmarklet: javascript:(function%20()%20%7B%20function%20SelectText(element)%20%7B%20var%20range%3B%20var%20selection%3B%20if%20(document.body.createTextRange)%20%7B%20range%20%3D%20document.body.createTextRange()%3B%20range.moveToElementText(element)%3B%20range.select()%3B%20copy2clipboard(range.text%2C%20element.innerHTML)%3B%20document.getSelection().removeAllRanges()%3B%20%7D%20else%20if%20(window.getSelection)%20%7B%20selection%20%3D%20window.getSelection()%3B%20range%20%3D%20document.createRange()%3B%20range.selectNodeContents(element)%3B%20selection.removeAllRanges()%3B%20selection.addRange(range)%3B%20copy2clipboard(selection.toString()%2C%20element.innerHTML)%3B%20selection.removeAllRanges()%3B%20%7D%20%7D%3B%20function%20copy2clipboard(text%2C%20html)%20%7B%20function%20listener(e)%20%7B%20e.clipboardData.setData(‘text%2Fplain’%2C%20text)%3B%20e.clipboardData.setData(‘text%2Fhtml’%2C%20html)%3B%20e.preventDefault()%3B%20%7D%20document.addEventListener(‘copy’%2C%20listener)%3B%20document.execCommand(‘copy’)%3B%20document.removeEventListener(‘copy’%2C%20listener)%3B%20%7D%3B%20%24(‘%23notebook-container’).on(‘mouseenter’%2C%20’.input%2C%20.output_wrapper’%2C%20function%20()%20%7B%20if%20(%24(this).find(‘i%3Alast’).length)%20%7B%20%24(this).find(‘i%3Alast’).show()%3B%20%7D%20else%20%7B%20%24(this).css(%7B%20’position’%3A%20’relative’%20%7D).append(%24(‘%3Ci%20style%3D%22position%3Aabsolute%3B%20top%3A7px%3B%20left%3A%207px%3B%22%20class%3D%22fa-copy%20fa%22%3E%3C%2Fi%3E’).on(‘click’%2C%20function%20()%20%7B%20SelectText(%24(this).parent().find(‘.input_area%2C%20.output’)%20%5B0%5D)%3B%20%24(this).slideUp()%3B%20%7D))%3B%20%7D%20%7D)%3B%20%24(‘%23notebook-container’).on(‘mouseleave’%2C%20’.input%2C%20.output_wrapper’%2C%20function%20()%20%7B%20%24(this).find(‘i%3Alast’).hide()%3B%20%7D)%3B%20%7D)%20()%3B Add it to your bookmarks and run it on a notebook page. How it works For every input and output cell it adds a small … Read more

Can python send text to the Mac clipboard

How to write a Unicode string to the Mac clipboard: import subprocess def write_to_clipboard(output): process = subprocess.Popen( ‘pbcopy’, env={‘LANG’: ‘en_US.UTF-8’}, stdin=subprocess.PIPE) process.communicate(output.encode(‘utf-8’)) How to read a Unicode string from the Mac clipboard: import subprocess def read_from_clipboard(): return subprocess.check_output( ‘pbpaste’, env={‘LANG’: ‘en_US.UTF-8’}).decode(‘utf-8’) Works on both Python 2.7 and Python 3.4. 2021 Update: If you need to … Read more

How does Copy Paste of formatted text work?

The data on the clipboard is extended with FORMATETC records: http://msdn.microsoft.com/en-us/library/ms682177%28VS.85%29.aspx The FORMATETC record contains as first field a cfFormat member which describes the file format. cfFormat can be a predefined value like CF_UNICODETEXT or CF_BITMAP or an application defined type defined by e.g. Microsoft Word. In .NET you can apparently query the Clipboard object … Read more

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>

How to handle a blocked clipboard and other oddities

Another workaround would be to use Clipboard.SetDataObject instead of Clipboard.SetText. According to this MSDN article this method has two parameters – retryTimes and retryDelay – that you can use like this: System.Windows.Forms.Clipboard.SetDataObject( “some text”, // Text to store in clipboard false, // Do not keep after our application exits 5, // Retry 5 times 200); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)