IE8 window.open 名称 - 不喜欢 JavaScript 编码?
我这样调用 window.open() :
window.open('blank.html', 'New_Window\x3a_Jamie', 'width=800,height=800');
我在代码中所做的就是获取窗口的名称,然后 JavaScript 使用 Microsoft Web 保护库。我还用下划线替换空格,因为我读到 IE 不喜欢窗口名称中的空格。仅供参考,原始字符串是“New Window: Jamie”,看起来“:”被编码为“\x3a”。窗口在 FireFox 中打开正常,但在 IE8 中打不开。 IE8 不喜欢这种编码、字符还是什么? IE8 的窗口名称中可以出现哪些字符有规则吗?
I'm calling window.open() like this:
window.open('blank.html', 'New_Window\x3a_Jamie', 'width=800,height=800');
What I've done in the code is taken the window's name and JavaScript encoded it using the Microsoft Web Protection library. I'm also replacing spaces with underscores because I read that IE doesn't like spaces in window names. FYI the original string was "New Window: Jamie" and it looks like the ":" gets encoded as "\x3a". The window opens in FireFox just fine, but the window does not open in IE8. Does IE8 just not like this encoding, or the character or what? Are there rules around what characters can appear in the window name for IE8?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。尽管似乎没有文档记录,但 IE 始终要求窗口名称由字母数字和下划线组成。无论是否从编码的字符串文字中读取,都不会接受冒号。
如果您确实需要将任意字符串映射到唯一的名称安全版本,则必须执行一些操作,例如将每个非字母数字字符编码为转义序列,例如:
我同意卡萨布兰卡,但实际上您似乎不太可能这样做需要这样做。用户永远不会看到窗口名称,因此
w1
也同样好。您需要窗口名称的情况非常罕见。Yes. Although it doesn't seem to be documented, IE has always required that a window name be composed of alphanumerics and underscore. A colon won't be accepted, whether read from an encoded string literal or not.
If you really needed to map an arbitrary string to a unique name-safe version you'd have to do something like encoding every non-alphanumeric character into an escape sequence, eg:
I agree with casablanca though, it seems very unlikely you should actually need to do this. The user is never going to get to see the window name, so
w1
is just as good. It's rare enough that you need window names at all.我认为它希望窗口名称能够作为标识符。因此,“New_Window_Jamie”可能没问题。
I think it wants the window name to be something that'd work as an identifier. Thus, "New_Window_Jamie" would probably be OK.
您真的需要窗口名称吗?来自文档:
这是指定名称的唯一用途,虽然我没有看到除了“无空格”之外的任何限制,但只使用字母、数字和下划线是安全的。
Do you really need a window name? From the docs:
That's about the only use of specifying a name, and though I don't see any restrictions apart from "no spaces", it would be safe to just stick to letters, digits and underscores.