如何在MFC中调用Javascript函数?

时间:2011-05-05 03:51:48

标签: javascript mfc

我正在创建一个发送邮件的程序。我想使用Javascript来验证电子邮件ID。谁能说如何从MFC调用Javascript函数?

1 个答案:

答案 0 :(得分:2)

将Javascript打包成Windows Script Component,然后通过COM调用它。

<?xml version="1.0"?>

<package>
  <component id="Lovesall.Com.EmailValidator">

    <comment>
      Descriptive comment goes here.
    </comment>

    <?component error="true" debug="true"?>

    <registration
        description="WSC Component for Email Validation"
        progid="Lovesall.Com.EmailValidator"
        version="1.00"
        classid="{a5ddfaa2-53de-40db-83f3-467914b4aeac}"
        remotable="False">

      <!-- boilerplate registration/unregistration logic -->
      <script language="VBScript">
        <![CDATA[

strComponent = "MyComponent"

Function Register
MsgBox strComponent & " - Script Component registered."
End Function

Function Unregister
MsgBox strComponent & " - Script Component unregistered."
End Function

        ]]>
      </script>
    </registration>


    <public>
      <method name="ValidateEmail">
        <parameter name="emailAddress"/>
      </method>
    </public>

    <script language="Javascript">
      <![CDATA[

        function ValidateEmail(emailAddress) {
          .... implementation here ...
        }

      ]]>
    </script>
  </component>
</package>