Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Active reading. Removed meta information (this belongs in comments). Dressed the naked link.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

Geesh, not sure why nobody pointed to this yet.

In 2018, folks, here's how you can go about it:

async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); }  catch (err) { console.error('Failed to copy: ', err); } } 

UsedIt is used in my Angular 6+ code like so:

<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> 

If I pass in a string, it copies it. If nothing, it copies the page's URL.

More gymnastics to the clipboard stuff can be done too. See more infoinformation here:

https://developers.google.com/web/updates/2018/03/clipboardapiUnblocking Clipboard Access

Geesh, not sure why nobody pointed to this yet.

In 2018, folks, here's how you can go about it:

async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); } catch (err) { console.error('Failed to copy: ', err); } } 

Used in my Angular 6+ code like so:

<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> 

If I pass in a string, it copies it. If nothing, copies the page's URL.

More gymnastics to the clipboard stuff can be done too. See more info here:

https://developers.google.com/web/updates/2018/03/clipboardapi

In 2018, here's how you can go about it:

async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); }  catch (err) { console.error('Failed to copy: ', err); } } 

It is used in my Angular 6+ code like so:

<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> 

If I pass in a string, it copies it. If nothing, it copies the page's URL.

More gymnastics to the clipboard stuff can be done too. See more information here:

Unblocking Clipboard Access

fixed wrong link
Source Link
KhoPhi
  • 9.6k
  • 18
  • 88
  • 139

Geesh, not sure why nobody pointed to this yet.

In 2018, folks, here's how you can go about it:

async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); } catch (err) { console.error('Failed to copy: ', err); } } 

Used in my Angular 6+ code like so:

<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> 

If I pass in a string, it copies it. If nothing, copies the page's URL.

More gymnastics to the clipboard stuff can be done too. See more info here:

http://localhost:4200/request/flutter-programmatically-trigger-futurebuilder-d160ad99https://developers.google.com/web/updates/2018/03/clipboardapi

Geesh, not sure why nobody pointed to this yet.

In 2018, folks, here's how you can go about it:

async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); } catch (err) { console.error('Failed to copy: ', err); } } 

Used in my Angular 6+ code like so:

<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> 

If I pass in a string, it copies it. If nothing, copies the page's URL.

More gymnastics to the clipboard stuff can be done too. See more info here:

http://localhost:4200/request/flutter-programmatically-trigger-futurebuilder-d160ad99

Geesh, not sure why nobody pointed to this yet.

In 2018, folks, here's how you can go about it:

async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); } catch (err) { console.error('Failed to copy: ', err); } } 

Used in my Angular 6+ code like so:

<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> 

If I pass in a string, it copies it. If nothing, copies the page's URL.

More gymnastics to the clipboard stuff can be done too. See more info here:

https://developers.google.com/web/updates/2018/03/clipboardapi

Source Link
KhoPhi
  • 9.6k
  • 18
  • 88
  • 139

Geesh, not sure why nobody pointed to this yet.

In 2018, folks, here's how you can go about it:

async copySomething(text?) { try { const toCopy = text || location.href; await navigator.clipboard.writeText(toCopy); console.log('Text or Page URL copied'); } catch (err) { console.error('Failed to copy: ', err); } } 

Used in my Angular 6+ code like so:

<button mat-menu-item (click)="copySomething()"> <span>Copy link</span> </button> 

If I pass in a string, it copies it. If nothing, copies the page's URL.

More gymnastics to the clipboard stuff can be done too. See more info here:

http://localhost:4200/request/flutter-programmatically-trigger-futurebuilder-d160ad99