<td><a href="javascript:void(0)" onclick="enterCampaign('5736785',event,0);"><img src="http://www.tup.365.com/sta_modifyprice.gif" width="20" height="20" title="进入"/></a></td>我想调用 enterCampaign 函数,请问用VC 怎么实现呀,以及怎么 event 是个什么类型的参数呀。参数怎么传递呀

解决方案 »

  1.   

    并且在 该页面的 html 代码中 并没有找到 enterCampaign 函数的声明。
      

  2.   

    http://blog.csdn.net/catxl313/article/details/2204541参考:
    从CDHtmlDialog调用网页中JavaScript函数的方法。其中pDoc指针参数可通过CDHtmlDialog::GetDHtmlDocument(&pDoc)函数获得;
    strFunctionName指示函数名;
    dispParams为传给函数的参数列表,其使用方法请查阅MSDN相关文档;
    varResult为函数返回值;
    exceptInfo为JavaScript函数执行时抛出的异常;
    nArgErr返回第一个出错的参数的下标,由于参数列表中参数的逻辑顺序为JavaScript函数定义的参数的顺序的逆序,所以应特别注意该返回值所指示的具体位置。HRESULT CallJSFunction(IHTMLDocument2* pDoc2,
                                     CString strFunctionName,
                                     DISPPARAMS dispParams,
                                     VARIANT* varResult,
                                     EXCEPINFO* exceptInfo,
                                     UINT* nArgErr )
    {
        IDispatch *pDispScript = NULL;   
        HRESULT hResult;
        hResult = pDoc2->get_Script(&pDispScript);
        if(FAILED(hResult))
        {
            return S_FALSE;
        }
        DISPID   dispid;   
        CComBSTR objbstrValue = strFunctionName;
        BSTR bstrValue =  objbstrValue.Copy();
        OLECHAR   *pszFunct   =  bstrValue ; 
        hResult   =   pDispScript->GetIDsOfNames(IID_NULL, 
                                                                 &pszFunct, 
                                                                 1,
                                                                 LOCALE_SYSTEM_DEFAULT, 
                                                                 &dispid);   
        if   (S_OK   !=   hResult)   
        { 
            pDispScript->Release();   
            return   hResult;   
        }      varResult->vt = VT_VARIANT;
        hResult   =   pDispScript->Invoke(dispid,
                                                  IID_NULL, LOCALE_USER_DEFAULT,
                                                  DISPATCH_METHOD,
                                                  &dispParams,
                                                  varResult,
                                                  exceptInfo,
                                                  nArgErr);  
        pDispScript->Release();
        return hResult;
    }
      

  3.   

    至于event的类型,就要看enterCampaign的实现
    在html中没找到,可能包含在html中引用的某个.js脚本文件中
      

  4.   

    本人学过WEB开发,还有一种可能是enterCampaign的实现
    在内存里面,页面和JS脚本都看不倒,这基本上是通过eval这个函数实现的,比如AJAX从服务端获取enterCampaign函数的代码,再eval,内存中就有了enterCampaign
      

  5.   

    2楼的我想问下调用pDispScript->Invoke(dispid,
                                                  IID_NULL, LOCALE_USER_DEFAULT,
                                                  DISPATCH_METHOD,
                                                  &dispParams,
                                                  varResult,
                                                  exceptInfo,
                                                  nArgErr); 
    函数后,当dispparams中有多个数据的时候,在javascript代码中怎么接收dispparams传来的全部数据啊???
    最好有javascript函数的demo,小弟试了下,dispparams中有多个数据的时候,怎么只能接收第一个数据啊,javascript函数为:
    function test(str)
    {
       alert(str);
    }
    这函数该怎么写???望指教
      

  6.   

    一种最简单的取巧方法
    让你的控件导航这么一个URL
    "javascript:document.getElementById('点击的超链接的ID').click();"
    就可以了其中,需要网页配合,给你要点击的超链接加个id或者说你用JS里面的遍历方法找到你的超链接这个元素,然后直接调click事件
    记住是用JS语句来写
    用VC控制Navigate,参数是"javascrip: ... "
      

  7.   


    void CTest_jsDlg::OnBnClickedButton2()
    {
    IHTMLDocument2 *pHTMLDocument=NULL; 
    if (!(pHTMLDocument = (IHTMLDocument2*)m_Ie.get_Document()))
    return;
    CString sScript = L"AddMsg(1,\'zxc\',\'11:25\',\'sdfsdfsdf\',0)";//此处为要调用的js函数
    CString Type = L"javascript";
    IHTMLWindow2   *m_pHtmlWindow=NULL;
    pHTMLDocument->get_parentWindow(&m_pHtmlWindow);
    VARIANT ret;
    ret.vt = VT_EMPTY;
    BSTR bstr = sScript.AllocSysString();
    BSTR btype = Type.AllocSysString ();
    m_pHtmlWindow->execScript(bstr,btype , &ret);
    ::SysFreeString(bstr);
    ::SysFreeString(btype);
    }
      

  8.   

    else  // 非第一次调用
    {
    CComQIPtr<IHTMLWindow2> m_ptrHtmlWnd;
    CComQIPtr<IHTMLDocument2> m_ptrHtmlDoc;

    IDispatch *pDispDoc = m_ieVideo.GetDocument();
    m_ptrHtmlDoc = pDispDoc;
    pDispDoc->Release();

    if (!m_ptrHtmlDoc) 
    return 0;  

    m_ptrHtmlDoc->get_parentWindow(&m_ptrHtmlWnd);
    CString strJS2;
    strJS2.Format("playVideo(\"%s\",\"%s\",\"%s\",\"%s\")",
    m_Global.m_Config.m_strSysName,
    m_Global.m_Config.m_strPassword,
    m_Global.m_Config.m_strCitizenID,
    strCameraID);
    _variant_t varRet;
    HRESULT hr = m_ptrHtmlWnd->execScript(
    CComBSTR(strJS2), CComBSTR("JScript"), &varRet);
    }