分享到line
```html
<div id="myDiv">這是想要分享到 LINE 的文字內容!</div>
<button onclick="shareToLine()">分享到 LINE</button>
<script>
function shareToLine() {
// 1. 取得 div 內的文字
const textToShare = document.getElementById('myDiv').innerText;
// 2. 將文字進行 URL 編碼
const encodedText = encodeURIComponent(textToShare);
// 3. 使用全形符號概念組合字串(實際執行時轉回標準網址以利瀏覽器喚醒 App)
const baseUrl = "https://line.me/R/msg/text/?";
const lineUrl = baseUrl + encodedText;
// 4. 開啟新分頁以喚醒 LINE
window.open(lineUrl, '_blank');
}
</script>
```
留言
張貼留言