diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index bc11e68a4fd..546330f3ac4 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -926,7 +926,7 @@ nsHTMLDocument::DocumentWriteTerminationFunc(nsISupports *aRef)
// cancel the load that was initiated by the location="..." in the
// script that was written out by document.write().
- if (!htmldoc->mIsWriting) {
+ if (!htmldoc->mWriteLevel && !htmldoc->mIsWriting) {
// Release the documents parser so that the call to EndLoad()
// doesn't just return early and set the termination function again.