When i use encodeURIComponent to encode the body as shown below, and if the body has spaces in it, the resulting link is broken and appears as follows :
http://www.sample.com/sample/explore?itemId=123&type=sample&name=name with space
body = "http://www.sample.com/sample/explore?itemId=123&type=sample&name=name with space"
var newLink = "mailto:?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);
window.location = newLin
How can i fix it and create a valid url?
console.log shows the encoded url correctly but in outlook the link is broken. It should appear as a proper hyperlink Have you made sure that its not because of the browser displaying the unescaped version in the address bar?
以上就是encodeURIcomponent while constructing mailto link的详细内容，更多请关注web前端其它相关文章！