最后,我已经弄清楚为什么contentWindow
要返回一个 void 元素。这是获取 iframe 文档的代码:
STRINGZ_TO_NPVARIANT("IFRAME", searchString);
NPN_Invoke(instanceNPP,NPVARIANT_TO_OBJECT(document), NPN_GetStringIdentifier("getElementsByTagName"), &searchString, 1, &frameCollection);
if (!NPN_GetProperty(instanceNPP, NPVARIANT_TO_OBJECT(frameCollection), NPN_GetStringIdentifier("length"), &lenght))
{
return;
}
for (int i=0; i<NPVARIANT_TO_INT32(lenght); i++)
{
INT32_TO_NPVARIANT(i, index);
if (!NPN_Invoke(instanceNPP, NPVARIANT_TO_OBJECT(frameCollection), NPN_GetStringIdentifier("item"), &index, 1, &frameItem))
{
continue;
}
if (!NPN_GetProperty(instanceNPP, NPVARIANT_TO_OBJECT(frameItem), NPN_GetStringIdentifier("contentWindow"), &contentWindow))
{
continue;
}
if (!NPN_GetProperty(instanceNPP, NPVARIANT_TO_OBJECT(contentWindow), NPN_GetStringIdentifier("document"), &frameDocument))
{
continue;
}
//do something with the frame's document
}