IE 11 中的 GWT Window.open 错误解释了查询参数 &deg=123

GWT Window.open in IE 11 misinterprets query parameter &deg=123

GWT 应用程序中,我尝试打开一个 Window 并传递包含查询参数的 url。碰巧有一个参数被命名为:deg_test,因此格式化后的 url 类似于:http://localhost:8888/mymodule/search?param1=value1&param2=value2&deg_test=123

ChromeFirefox 中,window 按预期打开,但是在 IE 11 中, &deg_ 部分被误解为 ° 并且它被转换为度数符号 (º) 并打破 url!

示例代码:

String query = "?param1=value1&param2=value2&deg_test=123";
com.google.gwt.user.client.Window.open("http://localhost:8888/mymodule/search"
                    + URL.encode(query), "_blank", "resizable=yes"

IE window URL: http://localhost:8888/mymodule/search?param1=value1&param2=value2°_test=123

如果我使用 URL.encodeQueryString 方法而不是 URL.encode 方法,?& 都将被编码并且服务器将抱怨 404

实际上这不是 GWT 问题,只是 IE 的一般问题。它将转换任何看起来像实体的东西(末尾没有 ;),例如: &deg&lt&gt 分别为 °<>。参见 this question

作为快速解决方法,我建议您将 deg_test 参数放在查询的开头。这样你就不会得到 &deg 片段,而是 ?deg

?deg_test=123&param1=value1&param2=value2

它会起作用。