0

当使用 Javascript 将用户重定向到另一个页面(分配给 document.location)时,我注意到 Javascript 会将您传递到 URL 的任何反斜杠字符转换为正斜杠字符。

例如,给定这个示例 HTML 文档

<html>
<head>
</head>

<body>
    <input type="button" id="takemeto" value="hello" onclick="document.location = '/hello\\world';" />
</body>
</html>

它应该尝试加载的预期 URL 是“/hello\world”,但是它实际尝试加载的 URL 是“/hello/world”。这个问题似乎只发生在 Safari 中,因为 Firefox 似乎正确地维护了我的 URL。

我的问题是,有没有办法在跨浏览器的 Javascript 中执行重定向,并且可以在我的 URL 中保留反斜杠字符?

4

1 回答 1

2

You can try percent-encoding the character:

document.location = '/hello%5Cworld'
于 2013-09-15T14:04:10.443 回答