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



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);
}

Angus

"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:#$R#QJWdHHA.4684@xxxxxxxxxxxxxxxxxxxxxxx
Angus <nospam@xxxxxxxxx> wrote:
What I really would like to do is be able to enumerate an HTML page
and find any scripts and then find the function names and parameters
and be able to display them.

All functions and all global variables are properties on the global
script object. You get this object with IHTMLDocument::get_Script. Query
for IDispatchEx, use GetNextDispID to enumerate all properties,
GetMemberName to get the name of the property. You should be able to use
GetMemberProperties (in particular fdexPropCanCall flag) to distinguish
between functions and global variables (but I haven't tried it myself).

I'm not sure how to get the parameter list. One thing to try: get the
function object off the global script object (call Invoke or InvokeEx
with the function's DISPID and DISPATCH_PROPERTYGET flag). You should
get an IDispatch* representing the function. Call toString() method on
it, via late binding, you should get a textual representation of the
functon, as it appears in script code. It should not be too difficult to
parse the header and extract parameter list.
--
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




.



Relevant Pages