简体   繁体   English

如何从ActiveX或DLL调用Javascript函数

[英]How to call Javascript function from activex or dll

I found the similar questions how to call java script function from activex or dll in c# but this is not provide me solution.than i continue my searching finally i got msdn link on this 我发现了类似的问题如何从C#中的activex或dll调用Java脚本函数,但这不提供给我solution.than我继续我的搜索最后我在此获得了msdn链接

http://msdn.microsoft.com/en-us/library/ms171712.aspx http://msdn.microsoft.com/en-us/library/ms171712.aspx

To access DOM from a UserControl hosted in Internet Explorer 从Internet Explorer中托管的UserControl访问DOM

Create your own custom derived class of the UserControl class. 创建您自己的UserControl类的自定义派生类。 For more information, see How to: Author Composite Controls. 有关更多信息,请参见如何:编写复合控件。

Place the following code inside of your Load event handler for your UserControl: 将以下代码放入UserControl的Load事件处理程序中:

    HtmlDocument doc = null;

    private void UserControl1_Load(object sender, EventArgs e)
    {
        if (this.Site != null)
        {
            doc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
        }
    }

Unfortunately I am still unable to get DOM object in my class.I have try to see what i get in this.Site so i put it on a messagebox 不幸的是,我仍然无法在课堂上获得DOM对象。

   MessageBox.Show(this.Site.ToString());

which shows me strange thing that is 告诉我奇怪的是

System.Windows.Forms.Control+AxSourcingSite

please help me.. 请帮我..

Here is a example to call js function from active x: 这是一个从活动x调用js函数的示例:

Type typeIOleObject = "activity control object".GetType().GetInterface("IOleObject", true);  
            object oleClientSite = typeIOleObject.InvokeMember("GetClientSite",  
            BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public,  
            null,  
            control,  
            null);  

            IOleClientSite oleClientSiteoleClientSite2 = oleClientSite as IOleClientSite;  
            IOleContainer pObj;  
            oleClientSite2.GetContainer(out pObj);  

            //get Script set from page  
            IHTMLDocument2 pDoc2 = (IHTMLDocument2)pObj;  
            IHTMLWindow2 win2 = (IHTMLWindow2)pDoc2.parentWindow;  
             //string code="";
            win2.execScript(code, "javascript");  
            if (returnType == null)  
      [ComImport, Guid("00000118-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]  
    public interface IOleClientSite  
    {  
        void SaveObject();  
        void GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk);  
        void GetContainer(out IOleContainer ppContainer);  
        void ShowObject();  
        void OnShowWindow(bool fShow);  
        void RequestNewObjectLayout();  
    }  
      [ComImport, Guid("0000011B-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]  
    public interface IOleContainer  
    {  
        void EnumObjects([In, MarshalAs(UnmanagedType.U4)] int grfFlags,  
        [Out, MarshalAs(UnmanagedType.LPArray)] object[] ppenum);  
        void ParseDisplayName([In, MarshalAs(UnmanagedType.Interface)] object pbc,  
        [In, MarshalAs(UnmanagedType.BStr)] string pszDisplayName,  
        [Out, MarshalAs(UnmanagedType.LPArray)] int[] pchEaten,  
        [Out, MarshalAs(UnmanagedType.LPArray)] object[] ppmkOut);  
        void LockContainer([In, MarshalAs(UnmanagedType.I4)] int fLock);  
    }  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM