16,472
社区成员
发帖
与我相关
我的任务
分享
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> <Script language=JavaScript type=text/javascript></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 />
</Script> </p>
</body>
</html>