Posts

Showing posts with the label Clipboard

Copy Image To Clipboard From Browser In Javascript?

Answer : No, you can't copy images to the clipboard. Copying anything to the clipboard is a security limitation of every browser, but you may able to copy text to the clipboard in IE if they have the proper security settings. Here Mozilla lists some of the problems caused by programmatic access to the clipboard. Yes, most of the scripts supports text only. http://forums.mozillazine.org/viewtopic.php?f=25&t=1195035&start=0 The above site also discussing the same issue. The following site said related to security issues, http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard but this won't work in latest version of Mozilla. The last answer is from 2010 and browsers have changed a lot since then. With this simple function, you can copy whatever you want (text, images, tables, etc) (on your page) to the clipboard. The function receive the element id or the element itself. function copyElementToClipboard(element) { window.getSelection().removeAllRanges...

Copy To Clipboard With Break Line

Answer : You have a few problems with the code. First problem in your code is the $(element).text() jquery text() strips your code from html including the <br> tags. So there is no newlines in the clipboard text since all html newlines are stripped away.. so nothing to replace. If you want to keep <br> as newlines you need to use .html() and parse your text more manually. Second problem is that you use <input> tag. <input> tag is only single lines so u cant have any newline in there. you need to use <textarea> for the conversion. The last problem is as above that you also should use \r\n for windows users. I updated your snippet with a working version. function copyToClipboard(element) { var $temp = $("<textarea>"); var brRegex = /<br\s*[\/]?>/gi; $("body").append($temp); $temp.val($(element).html().replace(brRegex, "\r\n")).select(); document.execCommand("copy"); $temp.remove(); } $...

Copy / Paste Text Selections Between Tmux And The Clipboard

Answer : Use the following tmux.conf with copy-pipe in the new versions of tmux (1.8+): set -g mouse on # To copy: bind-key -n -t emacs-copy M-w copy-pipe "xclip -i -sel p -f | xclip -i -sel c " # To paste: bind-key -n C-y run "xclip -o | tmux load-buffer - ; tmux paste-buffer" prefix+[ into copy-mode select content with mouse(hold) M-w to copy that part into system clipboard C-y the paste it inside tmux, C-v to paste it inside other regular application like web browser. Please note that, with Tmux 2.4 (since this commit), the binding syntax has changed. I paraphrase this Github comment to summarise the change briefly: replace -t with -T replace vi-<name> with <name>-mode-vi prefix the command with send-keys -X I had: bind-key -n -t vi-copy Enter copy-pipe 'xclip -i -sel p -f | xclip -i -sel c' bind-key -n -t vi-copy MouseDragEnd1Pane copy-pipe 'xclip -i -sel p -f | xclip -i -sel c' which I needed to change to: bind-key -n -T ...

Copy To Clipboard Using Javascript In IOS

Answer : Update! iOS >= 10 Looks like with the help of selection ranges and some little hack it is possible to directly copy to the clipboard on iOS (>= 10) Safari. I personally tested this on iPhone 5C iOS 10.3.3 and iPhone 8 iOS 11.1. However, there seem to be some restrictions, which are: Text can only be copied from <input> and <textarea> elements. If the element holding the text is not inside a <form> , then it must be contenteditable . The element holding the text must not be readonly (though you may try, this is not an "official" method documented anywhere). The text inside the element must be in selection range. To cover all four of these "requirements", you will have to: Put the text to be copied inside an <input> or <textarea> element. Save the old values of contenteditable and readonly of the element to be able to restore them after copying. Change contenteditable to true and readonly to false . Create a ...