htm文件里的脚本如下:
<SCRIPT LANGUAGE="JavaScript" defer>
window.open('http://www.a1.cn/index.php?view=booklet&title='+encodeURIComponent  (external.menuArguments.document.title)+'&url='+encodeURIComponent(external.menuArguments.location.href),'add','height=300,width=700');
</script> 我的工程是ATL 的,不知道该如何执行里面的脚本
最好能有较详细的一个例子。

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc/?id=1486 这个例子就是用VC来调用javascript的,希望对LZ有用。
      

  2.   

    js函数如下:
    function openIE(){
    window.open('http://www.baidu.com','add','height=300,width=700');
    }
    CString strFunc = "function openIE(){window.open('http://www.baidu.com','add','height=300,width=700');}";
    调用的时候,有段代码:
    CComBSTR bstrMember(strFunc);
    DISPID dispid = NULL;
    HRESULT hr = spScript->GetIDsOfNames(IID_NULL,&bstrMember,1,
    LOCALE_SYSTEM_DEFAULT,&dispid);
    这样hr是错误的,
    这个strFunc是指什么,是整个函数的字符串,还是只有函数名的字串
    如果是只有函数名的,那么函数体又是什么怎么关联进去的呢?
      

  3.   

    http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399/
    这里有个很好的例子
      

  4.   

    m_ie是CWebBrowser2控件变量,
    void CTestDlg::OnOK() 
    {
    // TODO: Add extra validation here
    CWebPage web ;
    web.SetDocument(m_ie.GetDocument());
    web.CallJScript("jsFunction","这是javascript的jsFunction(values)函数调用");
    //CDialog::OnOK();
    }void CTestDlg::OnCancel() 
    {
    // TODO: Add extra cleanup here
    CWebPage web ;
    web.SetDocument(m_ie.GetDocument());
    web.CallJScript("test","这是javascript的test()函数调用");
    //CDialog::OnCancel();
    }网页是加载本地网页文件,使用绝对路径
    CString pszUrl;
    pszUrl="javascript.html";
    CString strPath,str;
    DWORD dwSize=MAX_PATH;
    ::GetModuleFileName(NULL,strPath.GetBuffer(MAX_PATH),dwSize); //AfxGetResourceHandle()
    strPath.ReleaseBuffer(dwSize);
    str=strPath.Left(strPath.ReverseFind('\\')+1);
    if(pszUrl!="")
    {
    CString strUrl;
    strUrl=str+pszUrl;
    m_ie.Navigate(strUrl,NULL, NULL, NULL, NULL);
    }
    网页文件的内容
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>  <Script language=JavaScript type=text/javascript>  function jsFunction(values) //this function will be called from C++ codes
       {   alert(values);
       }  function test()
       {

     alert("test");
      }   </Script> 
    <body>
    <p>  &lt;Script language=JavaScript type=text/javascript&gt;</p>
    <p>  function jsFunction(values) //this function will be called from C++ codes<br />
        
      {</p>
    <p>  alert(values);<br />
        
      }</p>
    <p>  function test()<br />
        
      {<br />
      
     alert("test");</p>
    <p>  }<br />
        
      &lt;/Script&gt; </p>
    </body>
    </html>
      

  5.   

    http://download.csdn.net/source/2127345
      

  6.   

    CString pszUrl;
        pszUrl="javascript.html";
        CString strPath,str;
        DWORD dwSize=MAX_PATH;
        ::GetModuleFileName(NULL,strPath.GetBuffer(MAX_PATH),dwSize); //AfxGetResourceHandle()
        strPath.ReleaseBuffer(dwSize);
        str=strPath.Left(strPath.ReverseFind('\\')+1);
        if(pszUrl!="")
        {
            CString strUrl;
            strUrl=str+pszUrl;
            m_ie.Navigate(strUrl,NULL, NULL, NULL, NULL);
        }
    ______________________________________________________________
    这个是要先Navigate到javascript.html那个界面,然后再执行的,
    我要的是不跳到那个javascript.html界面了,就执行js了,这个能实现吗?
      

  7.   

    没浏览器加载网页,网页就是一个普通的文本文件,JavaScript的解释执行是需要浏览器的支持。
      

  8.   

    要是觉得碍眼,你可以把CWebBrowser2控件隐藏了。
      

  9.   

    刚说错了,刚问了下他们说只要有JavaScript 引擎支持就可以了,具体的你搜下,我不太清楚。