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.
Related
In chrome I use custom javascript for websites to copy paste a certain script I need to test in multiple browsers. In this case it;s simple and easy just click on the extension and the editor opens.
I need to do the same in firefox. I have tried this extension, but the documentation for it is very unclear. I am not sure how to open the editor to paste the java script code into it.
You can use GreaseMonkey Add On for running user-scripts with Firefox. Very popular and works well.
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?
I'm writing a simple Rich Text Editor which is currently working perfectly in Chrome and Firefox.
Internet Explorer however, is another story. I have finally managed to get most things working in IE with work-arounds and such, but all of my justify commands do nothing.
That is, this bit of code has no effect.
iframe.contentWindow.document.execCommand('justifyRight', false, null);
This is despite all other commands (ie: bold, italic, etc) working just fine.
Any clues as to why the justify* commands are different and not working?
I have a live demo available at http://www.hazaarmvc.com/site/test
Turns out that it was simply the content inside the editor window (an iFrame) that was the problem. It was originally generated using a Mozilla editor. Due to the differences in how each browser renders it's HTML content, IE just didn't know how to apply it's version of justifyleft, etc. Working on an empty editor everything just worked as expected.
See "Internet Explorer Differences" here: https://developer.mozilla.org/en/docs/Rich-Text_Editing_in_Mozilla for an explanation of what is different.
I'm going to chalk this one up to IE just being crap.
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.
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.