ActiveX×é¼þÓëJavaScript½»»¥
2007-10-24 23:55
1£®ÔÚCOM×é¼þÖе÷ÓÃJavaScriptº¯Êý
// Á¬½Óµã·½Ê½Ò³Ãæjavascript½Å±¾
<object classid="CLSID:B568F111-DFE4-4944-B67F-0728AB2AB30F" id="testCom" VIEWASTEXT></object>
<script language="JavaScript" for="testCom" event="staTe(s)">
alert("State(" + s + ")");
return 123;
</script>
<script language="JavaScript">
testCom.FireStateEvent("Hello");
</script>
// ʼþÊôÐÔ·½Ê½Ò³Ãæjavascript½Å±¾
function onState(s){
alert("onState(" + s + ")");
return 456;
}
var o = new ActiveXObject("TestATL.TestCom");
o.onstaTe=onState;
o.FireStateEvent("Hello");
// Com×é¼þVC7.1 ATL´úÂë
__interface _ITestComEvents{
[id(1), helpstring("Stateʼþ")] HRESULT State([in] BSTR str);
};
__event __interface _ITestComEvents;
IDispatchPtr m_onState; // ʼþÊôÐÔ
STDMETHOD(get_onState)(IDispatch** pVal) {
*pVal = m_onState;
return S_OK;
};
STDMETHOD(put_onState)(IDispatch* newVal) {
m_onState = newVal;
return S_OK;
};
STDMETHOD(FireStateEvent)(BSTR str) {
__raise State(str); // ¼¤·¢Á¬½Óµãʼþ
CComVariant result;
CComVariant avarParams[1] = {str};
DISPPARAMS dispParams = {avarParams, NULL, 1, 0};
EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
&nb
Ïà¹ØÎĵµ£º
Ò»£¬¸ÅÊö
1£¬ÕýÔò±í´ïʽ£¬¿ÉÒÔ˵ÊÇÈκÎÒ»ÖÖ±à³ÌÓïÑÔ¶¼ÌṩµÄ»úÖÆ£¬ËüÖ÷ÒªÊÇÌṩÁ˶Ô×Ö·û´®µÄ´¦ÀíÄÜÁ¦¡£
2£¬ÕýÔò±í´ïʽÔÚÒ³Ãæ´¦ÀíÖеÄʹÓó¡¾°£º
1£©±íµ¥ÑéÖ¤¡£Ñé֤ijЩÓò·ûºÏijÖÖ¹æÔò£¬ÀýÈçÓʼþÊäÈë¿ò±ØÐëÊäÈëµÄÊÇÓʼþ¡¢ÁªÏµµç»°ÊäÈë¿òÊäÈëµÄ±ØÐëÊÇÊý×ֵȵÈ
2£©´¦ÀíDOMÄ£ÐÍ¡£ÀýÈçͨ¹ý±í´ïʽ¶¨Î»DOMÖеÄÒ»¸ö¶ÔÏó»òһϵÁ ......
±Õ°ü£¨closure£©ÊÇJavascriptÓïÑÔµÄÒ»¸öÄѵ㣬ҲÊÇËüµÄÌØÉ«£¬ºÜ¶à¸ß¼¶Ó¦Óö¼ÒªÒÀ¿¿±Õ°üʵÏÖ¡£
ÏÂÃæ¾ÍÊÇÎÒµÄѧϰ±Ê¼Ç£¬¶ÔÓÚJavascript³õѧÕßÓ¦¸ÃÊǺÜÓÐÓõġ£
Ò»¡¢±äÁ¿µÄ×÷ÓÃÓò
ÒªÀí½â±Õ°ü£¬Ê×ÏȱØÐëÀí½âJavascriptÌØÊâµÄ±äÁ¿×÷ÓÃÓò¡£
±äÁ¿µÄ×÷ÓÃÓòÎ޷ǾÍÊÇÁ½ÖÖ£ºÈ«¾Ö±äÁ¿ºÍ¾Ö²¿±äÁ¿¡£
JavascriptÓïÑÔµÄÌØÊâÖ®´¦£¬¾ÍÔÚÓ ......
×î¶ÌµÄÍ϶¯´úÂë
<!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=gb2312" />
<script l ......
1. ±ê×¼µÄ·½·¨
<mce:script type="text/javascript"><!--
function openWin(src, width, height, showScroll){
window.showModalDialog (src,"","location:No;status:No;help:No;dialogWidth:"+width+";dialogHeight:"+height+";scroll:"+showScroll+";");
}
// --></mce:script> &n ......
1 ´´½¨½Å±¾¿é
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 Òþ²Ø½Å±¾´úÂë
1: <script language=”JavaScript”>
2: <!--
3: document.write(&ldquo ......