File tree 1 file changed +17
-3
lines changed
1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 34
34
</ aside >
35
35
< article >
36
36
< h2 > 1-3-111 window 物件</ h2 >
37
- < h3 id ="" > </ h3 >
37
+ < h3 > 開啟子頁籤 </ h3 >
38
38
< p >
39
39
現在有一個需求是要開啟子頁籤做其他操作,在母頁籤關閉時子頁籤也要跟著全部關閉以防使用者做出非預期地操作,實作方式如下:
40
40
</ p >
@@ -87,8 +87,22 @@ <h3 id=""></h3>
87
87
// 關閉主畫面時連帶把由主畫面開啟的子畫面一並關閉
88
88
window.addEventListener("beforeunload", closeAllSubWindows)
89
89
</ code > </ pre >
90
-
91
- < div class ="border-block "> </ div >
90
+ < h3 > 複製事件</ h3 >
91
+ < p >
92
+ 有時候使用者複製一段內容,貼上時會看到貼上結果多了一些空白。這時候如果需要修改複製內容或者禁止複製可以使用下列方法。
93
+ </ p >
94
+ < p >
95
+ 客戶端如果是第一次使用當前頁面的複製功能,現代瀏覽器會先詢問使用者是否要開啟複製事件的權限。如果網站使用者不同意則以下範例會失效。
96
+ </ p >
97
+ < pre > < code class ="language-js ">
98
+ window.addEventListener('copy',async()=> {
99
+ let text = '' ;
100
+ await navigator.clipboard.readText().then(t=> {
101
+ text = t.trim().replaceAll(/\t/g,'');
102
+ })
103
+ navigator.clipboard.writeText(text);
104
+ })
105
+ </ code > </ pre >
92
106
</ article >
93
107
</ main >
94
108
</ body >
You can’t perform that action at this time.
0 commit comments