获取IE中输入的网址

本文探讨了使用C++和C#通过Windows API和UIAutomation类实现窗口操作的功能,具体展示了如何查找和操作特定窗口元素的过程,并通过消息传递获取窗口文本。
HWND hwnd=::FindWindow(_T("IEFrame"),NULL);
 if(hwnd)
 {
  HWND hwnd2=::FindWindowEx(hwnd,NULL,_T("WorkerW"),NULL);
  HWND hwnd3=::FindWindowEx(hwnd2,NULL,_T("ReBarWindow32"),NULL);
  HWND hwnd4=::FindWindowEx(hwnd3,NULL,_T("ComboBoxEx32"),NULL);
  HWND hwnd5=::FindWindowEx(hwnd4,NULL,_T("ComboBox"),NULL);
  HWND hwnd6=::FindWindowEx(hwnd5,NULL,_T("Edit"),NULL);

   char sz[255];
  ::SendMessage(hwnd6,WM_GETTEXT,255,(LPARAM)sz);
  AfxMessageBox(sz);
 }
}

上面的代码是C++来写的,其实都是调用WIndows API, 如果使用C#来编写,可以使用UIAutomation类来实现相同的功能,各位有兴趣,地话 ,可以自己研究一下
在HTML中获取input框输入值有多种方法,以下为你详细介绍: ### 使用JavaScript的`document.getElementById()`方法 若input元素有唯一的`id`属性,可使用`document.getElementById()`方法获取该元素,再通过`value`属性得到输入值。示例代码如下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <input type="text" id="myInput" value="示例文本"> <button onclick="getValue()">获取值</button> <script> function getValue() { var inputElement = document.getElementById('myInput'); var inputValue = inputElement.value; console.log(inputValue); } </script> </body> </html> ``` ### 使用JavaScript的`document.querySelector()`方法 `document.querySelector()`方法可通过CSS选择器选择元素,获取input元素的输入值。示例代码如下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <input type="text" class="inputClass" value="示例文本"> <button onclick="getValue()">获取值</button> <script> function getValue() { var inputElement = document.querySelector('.inputClass'); var inputValue = inputElement.value; console.log(inputValue); } </script> </body> </html> ``` ### 实时获取输入值 实时获取input输入框中的值需要`oninput`和`onpropertychange`属性来实现。由于`onpropertychange`属性为IE专属,而`oninput`属性支持大部分浏览器,包括IE9及以上的版本。示例代码如下: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <input type="text" oninput="showValue(this)" onpropertychange="showValue(this)"> <script> function showValue(input) { console.log(input.value); } </script> </body> </html> ``` ### 在ASP.NET后台获取input值 在ASP.NET中,若要在后台获取input的输入值,需要为它添加`id`和`runat="server"`两个属性,然后通过`id`对应的名称`.Value`来获取输入的值。示例代码如下: ```html <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <input type="text" id="myInput" runat="server" /> <asp:Button ID="btnGetValue" runat="server" Text="获取值" OnClick="btnGetValue_Click" /> </form> </body> </html> ``` ```csharp using System; using System.Web.UI; public partial class _Default : Page { protected void btnGetValue_Click(object sender, EventArgs e) { string inputValue = myInput.Value; Response.Write("输入的值是:" + inputValue); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值