在什么情况下 document.open() 会返回 null?

发布于 2024-12-03 17:27:17 字数 735 浏览 1 评论 0原文

我试图了解在 Internet Explorer 6 和 Windows XP 下运行的 JavaScript 密集型瘦客户端应用程序中看到的间歇性脚本错误。问题的根本原因是以下函数调用返回 null 值(但它确实成功且没有错误):

var doc = targetWindow.document.open("text/html","_replace");

其中 targetWindow窗口 对象。

targetWindowtargetWindow.document 都不是 null,所以我很难理解为什么这个调用会返回 null 。我对文档的解释是此方法不应返回 null。

这段代码多年来一直没有改变并且完美地工作 - 直到我明白为什么会发生这种情况之前,我不确定我该如何处理这个问题,或者可能发生了什么变化导致这种情况开始发生。

什么可能导致此函数调用返回 null?

I'm trying to understand an intermittent script error that I am seeing in a JavaScript intensive thin-client application running under Internet Explorer 6 and Windows XP. The root cause of the problem is that the following function call returns a null value (however it does succeed without an error):

var doc = targetWindow.document.open("text/html","_replace");

Where targetWindow is a window object.

Neither targetWindow nor targetWindow.document is null and so I'm struggling to understand why this call would return null. My interpretation of the documentation is that this method shouldn't ever return null.

This code has been unchanged and working perfectly for many years - until I understand why this is happening I'm not sure either how I might handle this, or what might have changed to cause this to start happening.

What might cause this function call to return null?

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

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

发布评论

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

评论(2

长途伴 2024-12-10 17:27:18

根据文档,您应该传递“replace”,而不是“_replace”。试试这个:

var doc = targetWindow.document.open("text/html", "replace");

既然你说你的代码已经工作了很多年,那么很可能有些东西已经改变了,上面的建议可能不是问题。不过,它仍然值得一试。

您最近是否更改了应用程序中使用的任何 js 文件/库?另外,您在页面中使用任何浏览器插件吗?其中任何一个的较新版本可能会以某种方式影响您对“document.open”的调用。

According to the documentation you should be passing "replace", not "_replace". Try this instead:

var doc = targetWindow.document.open("text/html", "replace");

Since you say your code has worked for years, then it is likely that something has changed and the above suggestion may not be the issue. However, it is still worth a try.

Have you changed any js files / libraries you are using in your application lately? Also, are you using any browser plugins within the page? It is possible that a newer version of either of these could be somehow affecting your call to "document.open".

給妳壹絲溫柔 2024-12-10 17:27:18

按照 W3C 标准,document.open() 没有任何参数。查看此链接:http://www. w3.org/TR/DOM-Level-2-HTML/html.html#ID-72161170

我建议您使用 W3C 文档而不是 Microsoft 的文档,因为使用 W3C 您确信它适用于所有现代浏览器,而微软以添加扩展而闻名,当然,这些扩展仅适用于他们自己的产品。它被称为 EEE(拥抱、延伸和熄灭)。

只需使用不带参数的 document.open() 即可。有一些方法可以操纵用户历史记录,但这被称为不良编程实践。历史记录是用户的私人数据,Web 应用程序不应尝试操纵它。

document.open() does not have any parameters by W3C standard. Check out this link: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-72161170

I recommend you to use W3C documentation instead of Microsoft's one because with W3C you are sure it works on all modern browsers, while Microsoft is well known for adding extensions that, of course, works only in their own products. It's called EEE (Embrace, extend and extinguish).

Simply use document.open() without arguments. There are ways to manipulate user history, but that's called bad programming practice. History is user's private data and web application should not try to manipulate it.

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