ngx-clipboard icon indicating copy to clipboard operation
ngx-clipboard copied to clipboard

Page is scrollto Top after use copyFromContent

Open luongngochuythanh opened this issue 5 years ago • 2 comments

I used copyFromContent function to copy a text. But after paste text, return to page and click to anywhere, the page will scroll to Top. This is what is used

public singleCopy(targetText) {
    if (targetText) {
      this.clipBoardService.copyFromContent(targetText);
    }
  }

Inview:

<div>
     <button class="btn btn-outline-secondary single-copy-btn"
                        (click)="singleCopy(employee['name'])">
      </button>
</div>

Chrome version: 79.0.3945.130 OS: macOS Mojave10.14.4

Does anyone have experience about this or know the way to solve this please help 🙇 ?

luongngochuythanh avatar Feb 07 '20 02:02 luongngochuythanh

Could you provide an example on stackblitz.com?

I think it is possible to fix that behavior by setting container to body.

<body #container>
    <button ngxClipboard [cbContent]="'target string'" [container]="container">Copy</button>
</body>

maxisam avatar Feb 07 '20 16:02 maxisam

I have a similar issue, the page was scrolling to the top after copying to clipboard and switching to another tab.

It could be solved using configure method. ClipboardService.configure({ cleanUpAfterCopy: true })

Leandro-C-Reis avatar Apr 26 '22 18:04 Leandro-C-Reis