whatsapp://send?从'&'文本剪切字符串性格到最后?
我正在尝试添加一个可以在WhatsApp中共享的链接:
I'm trying to add a link that can be shared in WhatsApp:
例如:
"whatsapp://send?text=http://www.example.com/products/women/dresses?sessionid=34567&source=google.com"
但是WhatsApp中发送的链接已从'&'中截断.直到最后.(第二个参数)
But the link that is sent in WhatsApp is truncated from the '&' until the end. (the second parameter)
当我尝试时会发生相同的事情:
The same thing happens when I try:
"WhatsApp://send?text=http://www.example.com/prod&ucts/"
(请注意在"prod& ucts"一词中间的&")&"后的文字被截断.
(note the '&' in the middle of the word 'prod&ucts') The text after the '&' is truncated.
任何建议为什么会发生这种情况以及如何解决?
Any suggestions why this is happening and how can I fix it?
它将被切断,因为'&'表示新的查询字符串参数.您可以使用 encodeURI
JavaScript函数对URL中的字符串参数进行编码来修复它.&字符将编码为%26".
It'll be cutting it off because an '&' denotes a new query string parameter. You can fix it by encoding the string parameter in your URL using the encodeURI
JavaScript function. The & character will encode to "%26".