如何避免在 javascript window.open 上剥离一层转义编码?

发布于 2024-11-19 01:36:34 字数 1186 浏览 0 评论 0原文

我们的网站第一次有一个包含多层编码的链接,需要存在该链接才能通过公司的身份验证门户。当用户从 window.open 函数复制目标并将其粘贴到文本编辑器中时,新窗口中显示的目标也是如此 - 当您比较两者时,窗口中显示的目标已被删除一层编码。

我们已经确定这种情况发生在客户端上,但没有人知道原因或如何解决它。这是一个常见问题吗?我们错过了什么?

示例:我们有一个 javascript 函数:

function OpenStandardWindow(url, h, w)
{
    var t = (screen.height / 2) - (h / 2) - 75;
    var l = (screen.width / 2) - (w / 2);
    window.open(url,"_blank","height=" + h + ",width=" + w + ",top=" + t + ",left=" + l + ",resizable=yes,scrollbars=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
}

它可以很好地处理没有转义编码的 URL。

但是当像这样的 URL http://www.site.com/dispatcher?realm=example&BaseURL=%25253dhttps%2525253a%2525252f%2525252fexample.domain.com..etc

窗口中出现的是: http://www.site.com/dispatcher?realm=example&BaseURL=%253dhttps%25253a%25252f%25252fexample.domain.com

注意,新的 URL 丢失了一层转义编码(即“25”)。

为什么会发生这种情况?

For the first time in our site we have a link that has several layers of encoding that needs to be there in order to get through the company's authentication portal. When the user copies the target from the window.open function and pastes it in text editor, ditto on the target that shows up in the new window--when you compare the two, the one that shows up in the window has been stripped of one layer of encoding.

We've determined that this is happening on the client-sdie, but no one knows why or what to do to work around it. Is this a common problem? What are we missng?

Example: we have a javascript function:

function OpenStandardWindow(url, h, w)
{
    var t = (screen.height / 2) - (h / 2) - 75;
    var l = (screen.width / 2) - (w / 2);
    window.open(url,"_blank","height=" + h + ",width=" + w + ",top=" + t + ",left=" + l + ",resizable=yes,scrollbars=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
}

which works great with URLs without escaped encoding.

but when a URL like this http://www.site.com/dispatcher?realm=example&BaseURL=%25253dhttps%2525253a%2525252f%2525252fexample.domain.com..etc.

what appears in the window is:
http://www.site.com/dispatcher?realm=example&BaseURL=%253dhttps%25253a%25252f%25252fexample.domain.com

Notice that the new URL has lost a layer of escape encoding (i.e. '25').

Why is this happening?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文