I have a twitter share button on my page. I use this code because I want a custom icon. My problem is I can't seem to add a hashtag into the custom text. Where it says 'custom text' is where I input my tweet.
<a class="icon-twitter" rel="nofollow"
href="http://twitter.com/"
onclick="popUp=window.open(
'http://twitter.com/intent/tweet?text= custom text',
'popupwindow',
'scrollbars=yes,width=800,height=400');
popUp.focus();
return false">
<i class="visuallyhidden"><img class="social-media" src="images/twitter.png"/></i>
</a>
You need to encode the
#
. This is because the#
will otherwise be treated as the hash part of the url, and not a part of thetext
querystring, just like a&
would be interpreted as a separator between two querystring parameters, rather than a part of the value, unless you encode it to%26
. If the "custom text" can be anything, useencodeURIComponent
:If the value will always be hard coded, replacing the
#
with%23
would do: