有一個頁面上有「share at whatsapp」按鈕。這將創建並執行一個URL,如:使用location.href或類似的方法打開一個URL後跟一個散列符號
的WhatsApp://發送文本=寫一些文字,然後鏈接 - http://link_to_this_page#something
的問題是,瀏覽器(我?現在只用Chrome進行測試)會自動從哈希標記中刪除。
我已經試過了基本的:
var href = 'whatsapp://send?text=Example text - ';
var uri = location.protocol + '//' + location.host + location.pathname + '#gm.';
location.href = href + uri;
我location.replace()
,location.assign()
和window.open()
沒有運氣嘗試過。
所以問題是,我該怎麼辦?使用哈希是必要的,因爲它告訴目標頁面它必須在javascript中做一些事情(這可能需要更多時間來改變)。
'document.location.href = 「你的網址」 + window.location.hash' – xdevs23