我发现了类似的问题how to call java script function from activex or dll in c#,但这不是我提供的解决方案。我继续搜索,最后我得到了msdn链接
http://msdn.microsoft.com/en-us/library/ms171712.aspx
从Internet Explorer中托管的UserControl访问DOM
创建自己的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));
}
}
不幸的是我仍然无法在我的课堂上获得DOM对象。我试着看看我在这里得到了什么。所以我把它放在了一个消息框上
MessageBox.Show(this.Site.ToString());
这显示了我奇怪的事情
System.Windows.Forms.Control+AxSourcingSite
请帮帮我..
答案 0 :(得分:0)
以下是从活动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);
}