diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index 50a9f670292..28059cce549 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -565,6 +565,11 @@ static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLoca
TRACE("(%p)->(%p)\n", This, p);
+ if(!This->doc_node->nsdoc) {
+ WARN("NULL nsdoc\n");
+ return E_UNEXPECTED;
+ }
+
return IHTMLWindow2_get_location(HTMLWINDOW2(This->window), p);
}
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index ea010c9043d..8cf678a2c65 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -6974,6 +6974,7 @@ static void test_docfrag(IHTMLDocument2 *doc)
{
IHTMLElement *div, *body, *br;
IHTMLElementCollection *col;
+ IHTMLLocation *location;
IHTMLDocument2 *frag;
HRESULT hres;
@@ -6995,6 +6996,11 @@ static void test_docfrag(IHTMLDocument2 *doc)
ok(hres == S_OK, "get_body failed: %08x\n", hres);
ok(!body, "body != NULL\n");
+ location = (void*)0xdeadbeef;
+ hres = IHTMLDocument2_get_location(frag, &location);
+ ok(hres == E_UNEXPECTED, "get_location failed: %08x\n", hres);
+ ok(location == (void*)0xdeadbeef, "location changed\n");
+
br = test_create_elem(doc, "BR");
test_node_append_child((IUnknown*)frag, (IUnknown*)br);
IHTMLElement_Release(br);