Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what situation would document.open() return 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?

like image 967
Justin Avatar asked Sep 06 '11 16:09

Justin


1 Answers

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".

like image 159
Chris Pietschmann Avatar answered Oct 18 '22 11:10

Chris Pietschmann