Re: Is it possible to enumerate all javascript scripts on a web page?



Well that's the thing. I don't see a very basic javascript function in my
page using this code. I would assume I should see it in there somewhere.

My function is so simple:

<script language="JavaScript">
function myfunction()
{
document.write("Hello World")
}
</script>


But it doesn't pick up
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:eynrhnhdHHA.4012@xxxxxxxxxxxxxxxxxxxxxxx
Angus <nospam@xxxxxxxxx> wrote:
I am really trying to get ALL the javascript functions that I can
possibly call on a particular web page. But using IHTMLDocument
get_Script I don't see a javascript function on the page called
myfunction() ?

My code is:

CComQIPtr<IHTMLDocument> spHTMLDoc = spDispDoc;
CComQIPtr<IDispatch> spScriptDisp;
CComQIPtr<IDispatchEx> spDispEx;
spHTMLDoc->get_Script(&spScriptDisp);
spDispEx = spScriptDisp;
DISPID dispid;
CComBSTR bstrName;
hr=spDispEx->GetNextDispID(fdexEnumAll, DISPID_STARTENUM, &dispid);
while (hr == NOERROR)
{
hr = spDispEx->GetMemberName(dispid, &bstrName);
DWORD dwProps;
spDispEx->GetMemberProperties(dispid, grfdexPropAll, &dwProps);
if (dwProps & fdexPropCanCall)
{
ATLTRACE("fdexPropCanCall\n");
ATLTRACE(W2T(bstrName));
ATLTRACE("\n");
}
hr = spDispEx->GetNextDispID(fdexEnumAll, dispid, &dispid);
}

I must admit I've never used GetMemberProperties. I hoped you can
distinguish functions from global variables this way, but maybe you
can't. You'll have to experiment. But the first question is, do you get
the right members at all? If you drop GetMemberProperties call, and just
log all dispids and names you get, what do you see?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925




.