joh*_* m. 7 javascript social encoding utf-8 web
我们正在使用他们的静态共享URL与TencentQQ实现共享功能.我们有一个编码的网址:" http://www.testurl.com/product/this-is-a-product-%E7%9F%AD%E8%A3%A4/id-000000 "
当使用以下链接通过腾讯QQ共享此链接时:http://share.vtqq.com/index.php?c = share&a = index&url = http://www.testurl.com/product/this-is-a-product - %E7%9F%AD%E8%A3%A4/ID-000000&标题=此%图20是%20A%20test&的AppKey = 000000000
您将在Feed上看到URL在普通话字符的开头被拆分.
我想在处理URL时他们正在使用decodeURIComponent,我注意到在Chrome的开发工具控制台中执行时效果相同:
我想这里的问题是 - 我在编码这个URL时做错了吗?有没有理由在普通话字符的开头拆分URL?
您的 URL 未编码,它看起来像是被编码的,因为它使用非 ASCII/非拉丁字符,任何内部包含另一个 URL 作为参数的 URL 都需要编码,长话短说,这里是解决方案:
function urlShare(url,title,appkey){
return 'http://share.v.t.qq.com/index.php?c=share&a=index&url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&appkey='+appkey
}
Run Code Online (Sandbox Code Playgroud)
只需使用 URL、Title 和 appkey 调用此函数即可(不知道 appkey 是否需要编码):
urlShare('http://www.testurl.com/product/this-is-a-product-%E7%9F%AD%E8%A3%A4','A Title','id-000000')
Run Code Online (Sandbox Code Playgroud)
它将返回一个实际有效的安全 URL。
归档时间: |
|
查看次数: |
156 次 |
最近记录: |