i具有以下HTML摘要,带有JavaScript嵌入单衬。
<div class="social_icon twitter" onclick="shareSocialWall('twitter','New Comment on xxxx - WTF, if the dancers don&acirc;&#128;&#153;t come in until 4ish','https:/xxxx')"></div>
如您所见,有一个onclick
事件是触发shareSocialWall
。这里重要的是文本dancers don&acirc;&#128;&#153;t
。
当文本传递给函数shareSocialWall
时,这将发生什么:
location='https://twitter.com/intent/tweet?text='+text+'&url='+encodeURIComponent(url);
问题是文本正在打破呼叫以执行此tweet
。有没有一种方法可以在JavaScript内部编码此文本,以免打破文本。
此文本的路径是:
- perl => encodes entities on comment text as xml node
- xslt => passes xml text to javascript function (uses disable output encoding which does nothing for this apparently)
- js => handles the text inside the shareSocialWall Function
您的文本似乎已经被弄糊,可能是错误的。
您只需用正则删除所有HTML实体:
var str = 'New Comment on xxxx - WTF, if the dancers don&acirc;&#128;&#153;t come in until 4ish';
console.log(str.replace(/&[^s]*;/g, ''));
请注意,这是非常激进的,可能会删除比您的文本确实编码不好的文本,例如缺少;
。