1,317
社区成员
发帖
与我相关
我的任务
分享<html>
<head></head>
<body>
<script type="text/javascript" language="javascript">
function fun(n)
{
alert(n + 100);
}
</script>
</body>
</html>__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
CppWebBrowser1->Navigate(WideString("C:\\ccrun\\123.htm"));
}
//---------------------------------------------------------------------------
#include <mshtml.h>
bool __fastcall CrnExecuteScript(IHTMLDocument2 *pDoc, String strScript, String strLang)
{
IHTMLWindow2 *pWin;
VARIANT vRet;
bool bRet = false;
if (pDoc != NULL)
{
try
{
pDoc->get_parentWindow(&pWin);
if (pWin != NULL)
{
try
{
pWin->execScript(WideString(strScript), WideString(strLang), &vRet);
bRet = true;
}
__finally
{
pWin = NULL;
}
}
}
__finally
{
pDoc == NULL;
}
}
return bRet;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
IHTMLDocument2 *spDoc = (IHTMLDocument2 *)(void *)CppWebBrowser1->Document;
if (spDoc)
{
CrnExecuteScript(spDoc, String("fun(10)"), String("javascript"));
}
}