Button to paste from clipboard for all browsers - javascript

Is it possible create a button that can be used to paste some clipboard text into a textbox using javascript?
In my project I'm using ZeroClipboard to copy any text that I want, but now I need to paste that information using a single button in other page without any copy page connection.
At the internet I found ways to do that, but it just works on IE and I need a cross browser solution (minimun IE, chrome and FF).
Can anyone help me?
Other info:
I'm using asp.net mvc 3

For security reasons, Javascript don't have access to clipboard.
ZeroClipboard uses Flash in order to copy the text to clipboard BUT for security reasons too, Flash can only write to clipboard, not read.
The only way to do it is using a Java applet.

Here is article/Tutorial explaining how to do it : http://www.dynamic-tools.net/toolbox/copyToClipboard/
But the best pratice is to have a textarea with the data to copy already selected. Because some browser will not let you change the value of the clipboard data.

Related

Clipboard copy-paste in JavaScript doesn't work in Edge browser?

I am aware of the fact that Clipboard API is currently not supported by edge browser. I am using document.execCommand() to do copy & paste. The copy functionality works fine. But the paste doesn't work. I am using a custom context menu to achieve copy and paste. Previouly I made use of Clipboard API for the functions, it was working flawlessly until Edge came up. I heard Clipboard API will be added in next Edge release. I even checked Zero clipboard from GitHub. But didn't get an appropriate way to implement "Paste" functionality. I just want to know is there any alternate way to achieve the same or by using ZeroClipboard.

Why can't we right-click paste into TinyMCE with paste plugin in Firefox?

It seems to be impossible to copy text and then paste it into a TinyMCE editor using right-click paste with Firefox if you have the "paste" plugin. Why is this?
I'm using:
Firefox 33.1.1 (although users have complained of the issue with FF 29)
TinyMCE 4.1.1 with the "paste" plugin
I can right-click paste into these without error:
an element with the contenteditable="true" attribute (same method as TinyMCE), tested on http://html5demos.com/contenteditable
a normal textarea
TinyMCE 4.1.1 without the "paste" plugin
Users have discussed on the TinyMCE forum as far back as 2007, and mention an alert that says "Copy/Cut/Paste is not available in Mozilla and Firefox" which I do not receive with FF 33. No one mentions why this problem occurs, and the TinyMCE admins claim "this is not a bug". I'm interested in knowing what change was made to either Firefox or TinyMCE that causes this, and why (security?).
This question -- tinymce mouse paste not working -- has an answer of how to fix the issue: remove the "contextarea" plugin or any plugin that is based on it. But I'm interesting in knowing why it happens in the first place.
A co-worker got me on the right track and I found these two links:
https://developer.mozilla.org/en-US/Firefox/Releases/29/Site_Compatibility#Security
The removal of allowclipboard policy support broke the copy/paste buttons on some rich text editors like CKEditor. The standard Clipboard API's click-to-copy support will be implemented in the near future. The general keyboard shortcuts, Ctrl+C and Ctrl+V, should always work.
http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard
By default, JavaScript is not allowed to read or set your clipboard data for security and privacy reasons. This is because websites scripts can erase and replace what you currently have in your clipboard (data loss issue) and they can read whatever you have in your clipboard (security and privacy issue); as such, you should grant access with caution.
Maybe someone with TinyMCE expertise can provide more information on how it accesses the clipboard.
Good follow-up questions might be: Why don't the other browsers do this? Why is ctrl+v safer?

Copying text to clipboard in Chrome extension

I'm writing a Google Chrome extension and I want to copy some text in clipboard in a content script. I tried selecting it and then document.execCommand('copy') - it doesn't work. I don't want Flash, because it's not easy and elegant way to achieve that. I tried background page and <input> - it doesn't work.
Is there any working, elegant and simple way to copy text to clipboard in Chrome extension? It may also use jQuery.
Regards
Here's some working (Coffeescript) code that does copy / paste: https://github.com/philc/vimium/blob/master/lib/clipboard.coffee
Note that the code above runs in the background page; there was a bug a while back which broke execCommand in content scripts, and I'm not sure if that was ever fixed.

Open HTML file in Mac's Text Edit from a web browser

I'd like to use Javascript (or perhaps some more suitable script?) to open an HTML file in Text Edit (I'm on a mac)
I have a local web page made using Text Edit with different tabs that link to more Text Edit files on the page.
I'd like some way of quickly opening the tabs in Text Edit from my browser, then I could edit the HTML files easily in Text Edit and when I refresh the browser it will display my newly edited tab.
Pretty sure this should be simple but I'm a total beginner at Javascript and apart from going through the W3Schools tutorials, I have no knowledge of JScript per se.
Thank you for any help with this in advance.
I don't think TextEdit has a web listener of that sort, like Twitter for Mac has for Safari. I think you would need AppleScript to be able to do this, and that would only be on your local machine.
...wat? Just get a good text editor. I recommend Sublime Text 2 or Espresso.

Javascript Bookmarklet to get current URL

How would I get the current URL with a javascript code that could be used in a bookmarklet? This code isn't working:
javascript:copy(window.location.href);
It needs to copy it to the clipboard. I need to support Firefox, Chrome and IE
To get the URL from any legit browser (Opera, Chrome) with a bookmarklet:
javascript:(function(s){try{s=document.selection.createRange().text}catch(_){s=document.getSelection()}prompt('','\n'+location+'\n'+s)})()
If you want to add the Page Title:
javascript:(function(s){try{s=document.selection.createRange().text}catch(_){s=document.getSelection()}prompt('',document.title+" "+'\n'+location+'\n'+s)})()
What about a dialog from which you can copy the current URL?
javascript:void(prompt("URL:", location.href))
The void part prevents the browser from navigating away when pressing OK or Cancel.
Putting the URL into the clipboard takes more work, and differs on distinct browsers. If you really want to put the data in the clipboard, mention the browsers you need to support.
There is no built-in function in JS called copy. If there is one in the page, then it should work.
So the page would need this code
How do I copy to the clipboard in JavaScript?

Categories