[英]Twitter web intent URL encoding not working
I have no idea what I'm doing wrong here. 我不知道我在这里做错了什么。 I'm trying to encode my URL with javascript. 我正在尝试使用javascript对我的网址进行编码。 But the URL never gets put into the tweet. 但URL永远不会被放入推文中。 I think it has something to do with some parameters in my URL having spaces. 我认为这与我的URL中有空格的一些参数有关。
https://twitter.com/intent/tweet?text=40%25%20Off%20Prom%20Tuxedo%20Rental&url=http%3A%2F%2Fexample.com%3A5757%2Fcoupon%3Fref_name%3DTest%20Name%26school%3DTest%20School https://twitter.com/intent/tweet?text=40%25%20Off%20Prom%20Tuxedo%20Rental&url=http%3A%2F%2Fexample.com%3A5757%2Fcoupon%3Fref_name%3DTest%20Name%26school%3DTest% 20School
If I take out the %20
's from my URL then it works... 如果我从我的网址中删除%20
,那么它可以工作......
https://twitter.com/intent/tweet?text=40%25%20Off%20Prom%20Tuxedo%20Rental&url=http%3A%2F%2Fexample.com%3A5757%2Fcoupon%3Fref_name%3DTestName%26school%3DTestSchool https://twitter.com/intent/tweet?text=40%25%20Off%20Prom%20Tuxedo%20Rental&url=http%3A%2F%2Fexample.com%3A5757%2Fcoupon%3Fref_name%3DTestName%26school%3DTestSchool
But I need to keep those spaces in there. 但我需要把那些空间留在那里。
This is the javascript code I have right now... 这是我现在的javascript代码......
var text = encodeURIComponent("40% Off Prom Tuxedo Rental");
var couponURL = encodeURIComponent("http://example.com/coupon/?ref_name=Test Name&school=Test School");
var twitterURL = "https://twitter.com/intent/tweet?text=";
var twitterURL = twitterURL+text+"&url="+couponURL;
In this situation, a percentage sign equals %25, so if you want to include the spaces in your tweet link, use %2520 instead of %20. 在这种情况下,百分比符号等于%25,因此如果要在推文链接中包含空格,请使用%2520而不是%20。 So wherever you were going to use %20, use %2520 instead. 因此,无论您何时使用%20,请改用%2520。
var text = "40% Off Prom Tuxedo Rental";
text = text.replace(/\s/g, "%2520")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.