From ffa70c3737fba9e2208ae1ad85d5c5b2e7184f69 Mon Sep 17 00:00:00 2001 From: moshaoying Date: Sun, 7 Feb 2021 15:33:43 +0800 Subject: [PATCH 1/2] feat: add container option --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 38b0680..cb94298 100755 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ function copy(text, options) { if (!options) { options = {}; } + options.container = options.container || document.body debug = options.debug || false; try { reselectPrevious = deselectCurrent(); @@ -69,7 +70,7 @@ function copy(text, options) { } }); - document.body.appendChild(mark); + options.container.appendChild(mark); range.selectNodeContents(mark); selection.addRange(range); @@ -102,7 +103,7 @@ function copy(text, options) { } if (mark) { - document.body.removeChild(mark); + options.container.removeChild(mark); } reselectPrevious(); } From adb048935bdfd26e7daf8a049d86c572426a8417 Mon Sep 17 00:00:00 2001 From: moshaoying Date: Sun, 7 Feb 2021 18:19:32 +0800 Subject: [PATCH 2/2] feat: modify index.d.ts --- index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/index.d.ts b/index.d.ts index 287a22e..b76404a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,6 +7,7 @@ interface Options { message?: string; format?: string; // MIME type onCopy?: (clipboardData: object) => void; + container?: HTMLElement } declare function copy(text: string, options?: Options): boolean;