Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paste function in jquery/java script on button click

I have a textbox for write website url.And I place a button beside that.

I want if a user copy a url from any place and click on that button then the copied url paste in that textbox.

Now I can use ctrl+v to paste the url in the text box.But then mobile user not able to use that. So I need on click on that button the copied url paste in textbox.

Any help highly appreciable and thanks in advance.

like image 957
amit ghosh Avatar asked May 18 '13 11:05

amit ghosh


1 Answers

Based upon many SO questions from the past...

  • JavaScript get clipboard data on paste event (Cross browser)
  • Get current clipboard content?
  • Is it possible to read the clipboard in Firefox, Safari and Chrome using Javascript?
  • How do I copy to the clipboard in JavaScript?

... the answer is probably "No, it's impossible."

I would suggest, though, that you've skipped an important step in your development process. The problem you face is that you want to allow mobile users to painlessly enter text (in particular, URLs, which are a pain to type) from other sources into a textbox on your site. Take a step back and look at other possible solutions to that problem that don't involve Javascript access to the user's clipboard.

In fact, the 'solution' you're currently trying to implement doesn't even help the user, because the 'click to paste' button is only helpful to a mobile user if they've already succeeded in copying something to their clipboard, and if they've managed that, then presumably they already know how the native Copy/Paste functionality of their phone browser works, so they don't need your button. There are two necessary steps in the user flow you've described: copying a URL from some other source, and pasting it on your site. Even if what you're currently asking for were possible, it could only possibly help you make the second step easier for the user.

Instead, I figure you should check how copy and paste work on different available brands of smart phones and their browsers. If any of them use obscure or opaque interfaces that you worry your users may be unfamiliar with, have a button near your text box that is shown only to users of those platforms that gives them platform-targeted instructions on how to use their native copy and paste functionality.

like image 123
Mark Amery Avatar answered Oct 20 '22 14:10

Mark Amery