Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "Copy" button for API key #466

Closed
bajiat opened this issue Sep 14, 2015 · 2 comments
Closed

Add a "Copy" button for API key #466

bajiat opened this issue Sep 14, 2015 · 2 comments
Assignees
Milestone

Comments

@bajiat
Copy link
Contributor

bajiat commented Sep 14, 2015

Figure out how make copying the API key to clipboard easier than having to highlight the key and then press Ctrl+C or use other methods for copying (context menu etc.) One option would be adding a "Copy" button next to API key on the Profile page.

@frenchbread
Copy link
Contributor

I did a little research on topic "copying value to clipboard" and it turns out that direct copying (or forcing copying) data to clipboard using JS function may not be supported by all browsers and can cause security vulnerabilities.

Anyhow, the solution I came up with is listed on stackoverflow:

var copyTextareaBtn = document.querySelector('.js-textareacopybtn');

copyTextareaBtn.addEventListener('click', function(event) {
  var copyTextarea = document.querySelector('.js-copytextarea');
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
});

So, if for some reason after copying it is not able to get the value, we can ask user to copy ket manually using alert() for instance.

@brylie Have you been suggesting some JS library that would be helpful?

@brylie
Copy link
Contributor

brylie commented Oct 27, 2015

Try Clipboard.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants