c 從IE瀏覽器獲取當前頁面的內容

2022-09-26 01:09:13 字數 1321 閱讀 9953

private void timer1_tick(object sender, eventargs e)

;requetresove(resolveparams);

}catch (exception ex)}}

else

_getdocument = false;

}else

}www.cppcns.com }

第11行的  gethtmldocumentformhwnd(getpointcontrol(mousepoint, false))  分解下,先從滑鼠座標獲取頁面的控制代碼:

public static intptr getpointcontrol(system.drawing.point p, bool allcontrol)

}return intptr.zero;

}接下來,根據控制代碼獲取頁面內容:

public static htmldocument gethtmldocumentformhwnd(intptr hwnd)

marshal.freehglobal(result);

return obj as htmldocument;

}大致原理:

給ie窗體傳送訊息,獲取到乙個指向 ie瀏覽器(非託管)的某個記憶體塊的指標,然後根據這個指標獲取到htmldocument物件。

這個方法涉及到win32的兩個函式:

[system.runtime.interopservices.dllimportattribute("user32.dll", entrypoint = "sendmessagetimeouta")]

public static extern int sendmessagetimeouta(

[inattribute()] system.intptr hwnd,

uint msg, uint wparam, int lparam,

uint fuflags,

uint utimeout,

system.intptr lpdwresult);

[system.runtime.interopservices.dllimportattribute("oleacc.dll", entrypoint = "objectfromlresult")]

public static extern int objectfromlresult(

int lresult,

ref guid riid,

int wparam,

[marshalas(unmanagedtype.idispatch), out]

out object pobject

);

C 獲取當前頁面的url

2 通過js獲取 thisdloc document.location thisurl document.url thishref document.location.href thissloc self.location.href thistloc top.location.href thispl...

c 獲取當前頁面的url資訊

測試url com 80 aaa a.aspx?id 5 name yh function getquerystring name var reg new regexp name var r window.location search substr 1 match reg if r null re...

js監聽頁面是否在瀏覽器當前頁面

在最近的乙個socket專案中,需要監聽客戶端是否已讀客服端傳送的訊息。這裡用到了html5中document新增了乙個事件 visibilitychange,這個事件在頁面前台或後台切換時被觸發,它也有個對應的屬性visibilitystate,用於檢測當前頁面的狀態值為hidden還是visib...