The Cut and Paste from the system clipboard does not seem to work?
For instance open a word doc and copy some text, these items in the clipboard will not be pasted into a WebGL build, but can be pasted into a Web Player build(both the same project with a UI inputfield).
None of the paste shortcuts work(Ctrl-V or Shift-ins) in a WebGL build, but Ctrl-V works in the Web Player.
Is this a limitation within WebGL ? Anyone had this work for them ?
One is that Unity would not correctly detect and handle key combinations in text fields in WebGL. This was partially caused by issues in our input code and partially caused by issues in the input wrappers provided by the emscripten javascript runtime. Both have been fixed and this will work in 5.1, allowing Copy/Paste to work between text fields in Unity.
The other part is allowing Copy/Paste to actually access the System clipboard to get text into or out of Unity from other windows/applications. Unfortunately, this is much more difficult as accessing the system clipboard is not generally possible from JavaScript due to security concerns (ie, to avoid a web page sniffing your credit card number from your clipboard). The only way to get this to work is to use an html text field instead of a unity one, which you can do from JavaScript code.
So my actual need for this is a bit different than the OPs.
Our game Play AdVenture Capitalist, a free online game on Kongregate doesn’t have Cloud storage for progress yet, even though it will sometime this summer/fall, until now, we used the system clipboard to allow players to “Export” the content of their PlayerPrefs to the clipboard, and email it to themselves, then login on another machine and “Import” from the clipboard.
It was a quick and dirty way of doing things, we use a TextEditor from UnityEngine to set the content, call .SelectAll(), and then .Copy(); then to paste we just do new TextEditor(); and then .Paste(); and get the .content.text;
Since Chrome is abandoning the webplayer this month and 60% of our paid web users come from Chrome, we’re trying WebGL.
So My users aren’t actually needing a textfield to type into and we don’t capture any keyboard input. So i’m assuming I need to create a hidden textfield much like they do here… Lucid i’m really not a javascript/html guy, just the guy that got stuck with porting our game to WebGL while the rest of the team is focused on our Mobile client which has a larger audience.
Yes, that makes sense. However, notice, that regardless of how you hack it with hidden text fields, you will only be able to use the clipboard when the user hits Cmd-C/Cmd-V. You cannot make a button which just fills data to the clipboard when the user clicks on it.
You can use a flash-based auto-clipboard mechanism for now. Chrome has a non-NPAPI flash implementation, and as far as I know Firefox is still allowing Flash for the time being.
Old topic but: Is there is a solution to this now? How about to pop up an html overlay that shows the text if the user presses control + c in a input text box? I used prompt to implement it. Works fine to do copy and paste but sadly stalls the whole game. I guess an experienced web developer could get this done in a better way.
I meant the “prompt()” method from js. I think it is normal that it stalls everything on the page. I will try a html overlay then. Would be great if Unity comes with something like that in the future.
So based on the replies, I believe it is not possible to make use of the clipboard on iOS and Android then? We are currently sitting in a situation where we would like to utilize the clipboard in order for players to exchange LevelIDs.
This is about browser games only. It sounds like you make unity apps for mobile devices? Mobile devices have usually the share functionality to do that. e.g. in Android you can use intends to share an id via facebook or any other messenger installed on the device.
This looks to be broken even if you try to do an HTML overlay. Selecting text in that overlay is not possible, something about the initialization of the webgl unity is messing up the ability to select a group of text.
If you notice on this page, you cannot select the title field (one word at a time works fine, but you can click and select a group of text), and this is the case for all html text you put on the page (in chrome at least). I ended up implementing it in a sort of hacky way by popping up an alert box with the text to select…
This is probably the default webgl template. Try removing
::-moz-selection
::selection
from the style.css
Edit: just had a look at the website. Doesn’t look like the default at all but could it be that those css commands get in somewhere? If I remove them in my template I can select and copy / paste
edit: looks like you have something like this: ;-webkit-user-select:none; in your css