diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index 690ab0803f9..20d1c74cc26 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -213,12 +213,12 @@ static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMe
static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
{
HTMLDocument *This = impl_from_IHTMLDocument2(iface);
+ HRESULT hres;
TRACE("(%p)->(%p)\n", This, p);
- *p = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
- IDispatch_AddRef(*p);
- return S_OK;
+ hres = IHTMLDocument7_get_parentWindow(&This->IHTMLDocument7_iface, (IHTMLWindow2**)p);
+ return hres == S_OK && !*p ? E_PENDING : hres;
}
static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index c4d30ca50d1..8c7548a1539 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -6925,6 +6925,7 @@ static void test_dom_implementation(IHTMLDocument2 *doc)
IHTMLDocument7 *new_document;
IHTMLLocation *location;
IHTMLWindow2 *window;
+ IDispatch *disp;
str = a2bstr("test");
hres = IHTMLDOMImplementation2_createHTMLDocument(dom_implementation2, str, &new_document);
@@ -6947,6 +6948,9 @@ static void test_dom_implementation(IHTMLDocument2 *doc)
hres = IHTMLDocument2_get_parentWindow(new_document2, &window);
ok(hres == E_FAIL, "get_parentWindow returned: %08x\n", hres);
+ hres = IHTMLDocument2_get_Script(new_document2, &disp);
+ ok(hres == E_PENDING, "get_Script returned: %08x\n", hres);
+
hres = IHTMLDocument2_get_location(new_document2, &location);
ok(hres == E_UNEXPECTED, "get_location returned: %08x\n", hres);