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 的,不知道该如何执行里面的脚本
最好能有较详细的一个例子。
<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 的,不知道该如何执行里面的脚本
最好能有较详细的一个例子。
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是指什么,是整个函数的字符串,还是只有函数名的字串
如果是只有函数名的,那么函数体又是什么怎么关联进去的呢?
这里有个很好的例子
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>
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了,这个能实现吗?