3
我工作的一個項目,我需要得到所有打開的標籤的網址,在瀏覽器(如谷歌Chrome,IE,火狐,...)獲取打開標籤頁的網址,瀏覽器
有沒有辦法使用c#或vb.net來做到這一點?
p.s.它是一個Windows窗體應用程序
我工作的一個項目,我需要得到所有打開的標籤的網址,在瀏覽器(如谷歌Chrome,IE,火狐,...)獲取打開標籤頁的網址,瀏覽器
有沒有辦法使用c#或vb.net來做到這一點?
p.s.它是一個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
火狐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 :
共享功能:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(_
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
ByVal childAfter As IntPtr, _
ByVal lclassName As String, _
ByVal windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
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)
這將是非常困難的事情。如果你解釋爲什麼你想要這樣做,以防有更好的方式做,它可能會有所幫助。 – PhonicUK
如果我創建了一個,我不會讓我的瀏覽器共享該信息。對我來說看起來並不安全... – kratenko
它特定於瀏覽器和可疑的可靠性; http://stackoverflow.com/questions/7814027/how-can-i-get-urls-of-open-pages-from-chrome-and-firefox注意與代理服務器方法有關的評論。 –