How to obtain iframe html document in NPAPI
I am trying to obtain the document inside a frame.
The following does not fail:
NPN_GetProperty(aInstance, windowObject, NPN_GetStringIdentifier("frames"), &frames))
but the following fails, returning a null element:
NPN_Invoke(aInstance, NPVARIANT_TO_OBJECT(frames), NPN_GetStringIdentifier("item"), &index, 1, ¤tFrame)
I've also tried to retrieve all elements with tag IFRAME
, but accessing contentWindow
or contentDocument
property returns a void element.
Are 开发者_运维技巧there any other approaches to this?
Finaly , i've figured out why contentWindow
was returning a void element.
Here's the code for obtaining an iframe document :
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
}
精彩评论