如何用VC++调用在网页中编写的Javascript语言,这个Javascript语言
实现的功能是弹出一个特殊风格的窗口(最近比较流行的)。
我在网页中已经实现了点击链接来调用这个Javascript语言代码。
实现的功能是弹出一个特殊风格的窗口(最近比较流行的)。
我在网页中已经实现了点击链接来调用这个Javascript语言代码。
解决方案 »
- RTSP/HTTP消息的长度
- 关于自定义头文件编译时连接时错误
- 急问,有关ComboBox
- 在线等我的CListView怎么只看到数据库的第一个字段“社团ID”(数据库中有3条记录,社团ID分别为1,2,3),而且三条记录第一字段内容都在一
- ?CRecordset中的什么方法能执行"desc xxx"语句,如果没有,有其他办法么?谢高人
- 如何使非模态对话自动适应窗口大小
- 如何比较两个不同的位图?然后将他们不同的地方再成一个位图存下来?
- 有人说COM就是DLL,对吗?若有 int **p; *p=NULL; 则**p是否等于*NULL,*NULL又为何物?我想将virtual HRESULT_stdcall QueryInterface(c
- MFC ODBC数据库连接
- 画一条曲线,如何算出“中心点”,然后按住这个“中心点”范围拖动!
- 高分求教!flexgrid上的CEdit控件数据刷新问题,解决问题上给分!
- COM方法中的参数问题
JavaScript call from C++
http://www.codeproject.com/com/JSCalls.asp
The information in this article applies to:Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 5.0--------------------------------------------------------------------------------
SUMMARY
When hosting the WebBrowser control in a Visual C++ application, you may wish to execute a script function that exists on a Web page. This article demonstrates how to do this. MORE INFORMATION
In order to call a script function that exists on a Web page, you have to use automation; in other words, IDispatch. Use the following steps to invoke a script function that exists on a Web page from your Visual C++ application: Get the IDispatch of the HTML document.
Call IDispatch::GetIDsOfNames to get the ID of the script function.
Call IDispatch::Invoke to execute the function.
The following Visual C++ source code demonstrates how to implement this in your own application. This code uses smart pointers created by the #import statement. You must include this #import statement in one of your source code files, preferably Stdafx.h: #import "C:\winnt\system32\mshtml.tlb" // location of mshtml.tlb void CMyClass::ExecuteScriptFunction()
{
// m_WebBrowser is an instance of IWebBrowser2
MSHTML::IHTMLDocument2Ptr spDoc(m_WebBrowser.GetDocument()); if (spDoc)
{
IDispatchPtr spDisp(spDoc->GetScript());
if (spDisp)
{
// Evaluate is the name of the script function.
OLECHAR FAR* szMember = L"evaluate";
DISPID dispid; HRESULT hr = spDisp->GetIDsOfNames(IID_NULL, &szMember, 1,
LOCALE_SYSTEM_DEFAULT, &dispid); if (SUCCEEDED(hr))
{
COleVariant vtResult;
static BYTE parms[] = VTS_BSTR; COleDispatchDriver dispDriver(spDisp); dispDriver.InvokeHelper(dispid, DISPATCH_METHOD, VT_VARIANT,
(void*)&vtResult, parms,
"5+Math.sin(9)");
}
}
}
} The following is the HTML for the Web page that contains the evaluate function:<HTML>
<HEAD>
<TITLE>Evaluate</TITLE> <SCRIPT>
function evaluate(x)
{
alert("hello")
return eval(x)
}
</SCRIPT>
</HEAD> <BODY>
</BODY>
</HTML> REFERENCES
This source code is based on the Visual Basic sample that appears in the March/April 1998 edition of MSDN News. Please refer to this edition for information about how to execute a script function from a Visual Basic application that is hosting the WebBrowser control. (c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation Additional query words: kbDSupport kbdsi Keywords : kbcode kbIE400 kbie401 kbWebBrowser kbGrpDSInet kbFAQ kbie500 kbDSupport kbieFAQ
Issue type : kbhowto
Technology : kbIEsearch kbAudDeveloper kbSDKIESearch kbSDKIE400 kbSDKIE401
Last Reviewed: July 18, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use. Disability/accessibility Privacy Policy