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

1 Answer 1

4

encodeURIComponent() your GET param (the tweet variable). Also, don't encode the GET params that you do want to have special meaning (the & and =).

jsFiddle.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.