2

I have the following tweet:

var tweet = "I might actually do a 5K: http://t.co/tXQIYlUt #zombies #running"

And I would like to pass this to the twitter api using js

$('.my_div').append('<a href="https://twitter.com/share?text='+ tweet +'%2Fpages%2Ftweet-button" target="_blank">Tweet</a>')

My JS creates this: https://twitter.com/share?text=I%20might%20actually%20do%20a%205K:%20http://t.co/tXQIYlUt%20#zombies #running&via=JustinZollars&url=

which renders this way at twitter.com:

I might actually do a 5K: http://t.co/tXQIYlUt http://mydomain.com/

notice it cut out my hash tags. how can I sanitize my url?

Resources:

  1. docs
4

1 に答える 1

4

encodeURIComponent()あなたのGETパラメータ(tweet変数)。また、特別な意味を持たせたい GET パラメータ (&および=) をエンコードしないでください。

jsFiddle .

于 2011-12-07T23:00:46.503 に答える