110,533
社区成员
发帖
与我相关
我的任务
分享
private SHDocVw.InternetExplorer getWindowObject(String ieWindowName)
{
if (ieWindowName == String.Empty || ieWindowName.Equals(""))
{
return null;
}
SHDocVw.InternetExplorer v_ie = null;
SHDocVw.ShellWindows sws = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer iew in sws)
{
if (iew.LocationURL.Contains(ieWindowName))
{
v_ie = iew;
}
}
return v_ie;
}
/// <summary>
/// 控制网页显示值
/// </summary>
/// <param name="strUrl">ie中的url</param>
/// <param name="strInputId">要设置的id</param>
/// <param name="strVal">值</param>
private void SetValue(String strUrl, String strInputId, String strVal)
{
SHDocVw.InternetExplorer iw = getWindowObject(strUrl);
if (iw != null)
{
HTMLDocument doc = (HTMLDocument)iw.Document;
((HTMLInputTextElement)doc.getElementById(strInputId)).value = strVal;
}
}
4. 调用方法 SetValue("http://www.baidu.com/", "kw", "test");
好了。在说明一下,ie下,打开url,才会有效果显示。
散分了。。。。。。。。。