Firefox 和在取消转义 ® 时神奇地出现的字符 (Â)

发布于 2024-07-18 10:10:14 字数 447 浏览 5 评论 0原文

我在 Firefox 中取消转义要以表单提交的 ® (注册字符),因为实际将该字符输入到 Javascript 中会导致脚本行为异常。

但是,我必须使用字符的未转义(..)版本,因为它被提交到后端(我无法控制)并且输出是一个 pdf 文件,该文件使用未转义的 ®以 pdf 形式显示。

我像这样对 ® 字符进行转义:

unescape("%AE")

但是...当我查看 pdf 文件中的 ® 时它显示为 ®,这只发生在 Firefox 中,不会发生在 Internet Explorer 中。

有办法让它在 Firefox 2/3 中工作吗?

谢谢,
   安德鲁

I'm unescaping an ® (registration character) in firefox to be submitted in a form, since actually typing that character into Javascript causes the script to behave strangely.

However, I must use the unescaped(..) version of the character since it is being submitted to the backend (where I have no control) and the output is a pdf file which uses the unescaped ® for display in a pdf.

I unescape the ® character like this:

unescape("%AE")

However...when I do view the ® in the pdf file it appears as ®, this only happens in Firefox, not in Internet Explorer.

Is there anyway of getting this to work in Firefox 2/3?

Thanks,
   Andrew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

背叛残局 2024-07-25 10:10:14

AFAIK,在取消转义之后,Mozilla 返回 ® 的 Unicode 表示形式,但 IE 不会。 (十六进制的“%C2%AE”,%C2 表示 PDF 中出现的奇怪字符 Â。)Internet Explorer 和 Mozilla 以不同的方式对字符串进行转义。 您应该设置显式字符编码,主要是 UTF-8。

MDC:转义和unescape函数

escape 和 unescape 函数
对于非 ASCII 不能正常工作
字符并已被弃用。
在 JavaScript 1.5 及更高版本中,使用
编码 URI、解码 URI、
编码 URIComponent,以及
解码URIComponent。

MSDN

unescape方法返回一个字符串
包含以下内容的值
字符串。 所有字符均已编码
%xx 十六进制形式是
替换为它们的 ASCII 字符集
等价物。

以 %uxxxx 格式编码的字符
(Unicode 字符)替换为
十六进制的 Unicode 字符
编码 xxxx。

AFAIK, after unescaping, Mozilla returns the Unicode representation of ®, but IE not. ("%C2%AE" in hex, and %C2 means that strange character  appearing in the PDF.) Internet Explorer and Mozilla unescapes strings in a different way. You should set an explicit character encoding, principally UTF-8.

MDC: escape and unescape Functions:

The escape and unescape functions do
not work properly for non-ASCII
characters and have been deprecated.
In JavaScript 1.5 and later, use
encodeURI, decodeURI,
encodeURIComponent, and
decodeURIComponent.

MSDN:

The unescape method returns a string
value that contains the contents of
charstring. All characters encoded
with the %xx hexadecimal form are
replaced by their ASCII character set
equivalents.

Characters encoded in %uxxxx format
(Unicode characters) are replaced with
the Unicode character with hexadecimal
encoding xxxx.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文