Why can't I use the character '|', in the same window when sharing

web

#1

Why can’t I use the character ‘|’, in the same window when sharing.

I’m trying to twitter share link via a tag.

For exapmle:

<a href="https://twitter.com/intent/tweet?url=https://twittercommunity.com&text=hoge|fuga">share me!</a>

If I use the character ‘|’, like ‘&text=hoge|fuga’, it can’t work.
And If I don’t use the character ‘|’, like ‘&text=hogefuga’, it works.

But If I use the character ‘|’, like ‘&text=hoge|fuga’ and add onClick attributes for opening a new window, then it works fine.

<a href="https://twitter.com/intent/tweet?url=https://twittercommunity.com&text=hoge|fuga"onClick="window.open(encodeURI(decodeURI(this.href)), 'tweetwindow', 'width=650, height=470, personalbar=0, toolbar=0, scrollbars=1, sizable=1'); return false;">share me!</a>

Why it occurs ???


#2

Hello fukaminmin,

I believe the reason is because ‘|’ needs to be url encoded as it is not a valid url character.

encodeURIComponent('|')
"%7C"

So your link would become:

<a href="https://twitter.com/intent/tweet?url=https://twittercommunity.com&text=hoge%7Cfuga">share me!</a>

Hope that helps!


#3

@indianburger
Thank you for your reply.

I understood!! :grinning:


#4