我尝试使用带有 chrome 的 npapi 通过标记名获取 dom 元素,但结果的长度始终为零。
NPVariant tagName;
STRINGZ_TO_NPVARIANT("input", tagName);
NPVariant inputCollection;
if(!NPN_Invoke(m_pNPInstance, doc,NPN_GetStringIdentifier("getElementsByTagName"), &tagName, 1, &inputCollection))
{
outLog<<"get input error"<<endl;
}
NPVariant npvlength;
if (NPN_GetProperty(m_pNPInstance, NPVARIANT_TO_OBJECT(inputCollection), NPN_GetStringIdentifier("length"), &npvlength))
{
outLog<<npvlength.type<<"," <<npvlength.value.intValue<<endl;
}
npvlength.value.intValue 始终为 0,但是当我尝试获取元素时就可以了。我可以得到元素和它的属性。
NPVariant index;
INT32_TO_NPVARIANT(0, index);
NPVariant Item;
if (NPN_Invoke(m_pNPInstance, NPVARIANT_TO_OBJECT(inputCollection), NPN_GetStringIdentifier("item"), &index, 1, &Item))
{
NPVariant typeVal;
if (NPN_GetProperty(m_pNPInstance, NPVARIANT_TO_OBJECT(Item), NPN_GetStringIdentifier("type"), &typeVal))
{
outLog<<NPVARIANT_TO_STRING(typeVal).UTF8Characters<<endl;
}
}