简体   繁体   English

Facebook Share JavaScript无法使用挪威语文字

[英]Facebook share javascript is not working with norwegian text

I have a javascript that looks like this: 我有一个JavaScript,看起来像这样:

<script type="text/javascript">
$(document).ready(function () {
   $('#share_button@(number)').click(function (e) {
   e.preventDefault();
   FB.ui(
{
    method: 'feed',
    name: '@(item.Title)',
    link: ' http://www.newsifi.com',
    picture: 'http:/url/img/bla.png',
    caption: 'demo',
    description: '@(item.Description)',
    message: ''
});
                    });
                });
</script>

@(item.Description) displays: @(item.Description)显示:

En person er hardt skadet etter en frontkollisjon mellom en campingbil og en annen bil på E6 sør for Otta i Gudbrandsdalen. 前往Otta i Gudbrandsdalen参加E6试玩的宾客。

When I check in chrome this is the error: 当我检查Chrome时,这是错误:

错误

So basicly the share function is not working anymore. 因此,基本上,共享功能不再起作用。

How can I fix this? 我怎样才能解决这个问题?

I have tried to change @(item.Description) to @Server.UrlEncode(item.Description) it works but it displays very weird in the facebook share popup. 我试图将@(item.Description)更改为@Server.UrlEncode(item.Description) ,但它在facebook共享弹出窗口中显示得很奇怪。

This is how it looks like: 它是这样的:

description: 'En+person+er+hardt+skadet+etter+en+frontkollisjon+mellom+en+campingbil+og+en+annen+bil+p%c3%a5+E6+s%c3%b8r+for+Otta+i+Gudbrandsdalen.%0a',

Any kind of help is appreciated! 任何帮助表示赞赏!

Note: 注意:

I checked how this javascript works with swedish text and it seems to work even if it looks like this SS. 我检查了此javascript如何与瑞典语文本一起使用,即使它看起来像这样的SS,它也似乎可以正常工作。

在此处输入图片说明

As you can clearly see from the generated source code, you have a newline inside your Javascript string literal. 从生成的源代码中可以清楚地看到,Javascript字符串文字中有一个换行符。

That isn't valid Javascript. 那不是有效的Javascript。

You need to Javascript-encode the string to escape characters like newlines that cannot appear in string literals. 您需要对字符串进行Javascript编码 ,以转义不能出现在字符串文字中的字符,例如换行符。
Call HttpUtility.JavaScriptStringEncode() . 调用HttpUtility.JavaScriptStringEncode()

UrlEncode() is wrong because this isn't a URL. UrlEncode()错误,因为这不是URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM