在浏览器中获取已打开选项卡的URL
我正在开发一个项目,我需要在浏览器中获取所有已打开标签的url(例如Google Chrome,IE,Firefox等)
有没有办法用c#或vb.net做到这一点?
ps它是一个Windows窗体应用程序
即:
Dim browser As SHDocVw.InternetExplorer Dim myLocalLink As String Dim myDoc As mshtml.IHTMLDocument2 Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindows() Dim filename As String For Each ie As SHDocVw.InternetExplorer In shellWindows filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower() If filename = "iexplore" Then browser = ie myDoc = browser.Document myLocalLink = myDoc.url MessageBox.Show(myLocalLink) End If Next
C#:
SHDocVw.InternetExplorer browser; string myLocalLink; mshtml.IHTMLDocument2 myDoc; SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); string filename; foreach (SHDocVw.InternetExplorer ie in shellWindows) { filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if ((filename == "iexplore")) { browser = ie; myDoc = browser.Document; myLocalLink = myDoc.url; MessageBox.Show(myLocalLink); }
你需要:
microsoft.mshtml
和
shdocvw.dll
FireFox c#:
using NDde.Client;
DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo"); dde.Connect(); string url = dde.Request("URL", int.MaxValue); dde.Disconnect(); MessageBox.Show(url);
下载NDde.2.01.0563(NDde.dll)
我也对Chrome做过:
Vb.net:
共享function:
_ Private Shared Function FindWindow( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As IntPtr End Function _ Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _ ByVal childAfter As IntPtr, _ ByVal lclassName As String, _ ByVal windowTitle As String) As IntPtr End Function _ Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr End Function
上述就是C#学习教程:在浏览器中获取已打开选项卡的URL分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
Dim h As IntPtr For Each p As Process In Process.GetProcessesByName("chrome") h = FindWindow("Chrome_WidgetWin_1", p.MainWindowTitle) Exit For Next Dim urlH As IntPtr urlH = FindWindowEx(h, 0, "Chrome_OmniboxView", Nothing) Dim urlHH As IntPtr = Marshal.AllocHGlobal(100) Dim NumText As Integer = SendMessage(urlH, &HD, 50, urlHH) Dim url As String = Marshal.PtrToStringUni(urlHH) MsgBox(url)
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1002530.html