Jump to content



Photo

_IENavigate_kill_popup function


  • Please log in to reply
1 reply to this topic

#1 Herb191

Herb191

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 27 October 2011 - 04:09 PM

I use a lot of IE functions in my scripts and find it really annoying when I try to use _IENavigate to leave a webpage and I get popups saying things like "Are you sure you want to leave this page?". I searched the forum and could not find a solution that I liked so I created this function. I hope others find it useful and as always I am open to any constructive criticism (that's how we learn). :D

_ProcessGetParent() function taken from MrCreatoR's post Here (thanks MrCreatoR)

AutoIt         
#include <IE.au3> ;This page currently has displays a popup when you try to navigate away from the page $any_url = "aquaponics4you.com" ;$any_url = "yahoo.com" $oIE = _IECreate($any_url) $oIE = _IENavigate_kill_popup($oIE, "Google.com") Func _IENavigate_kill_popup($IEObject, $URL, $visible = 1, $wait = 1)     If Not IsObj($IEObject) Then Return SetError(1, 0, 0)     $closed_process = False     ;gets the IE process     $pid = WinGetProcess(_IEPropertyGet($IEObject, "hwnd"))     ;Trys to navigate to URL     _IENavigate($IEObject, $URL, 0)     ;Gets list of all process     $aProc_List = ProcessList()     ;Checks to see if any process were opened by the IE window. If process where opened it closes them and the IE window.     For $i = 1 To $aProc_List[0][0]         If _ProcessGetParent($aProc_List[$i][1]) = $pid Then             ProcessClose($aProc_List[$i][1])             $closed_process = True         EndIf     Next     ;will create a new IE with old IE object varable if it no longer exists.     If $closed_process = True Then         $IEObject = _IECreate($URL, 0, $wait)         Return $IEObject     Else         If $wait = 1 Then _IELoadWait($IEObject)         Return $IEObject     EndIf EndFunc   ;==>_IENavigate_stop_pop Func _ProcessGetParent($iPID)     Local $wbemFlagReturnImmediately = 0x10     Local $wbemFlagForwardOnly = 0x20     Local $colItems = ""     Local $strComputer = "localhost"     $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")     $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)     If IsObj($colItems) Then         For $objItem In $colItems             If $objItem.ProcessID = $iPID Then Return $objItem.ParentProcessID         Next     EndIf     Return SetError(1, 0, 0) EndFunc   ;==>_ProcessGetParent

Edited by Herb191, 27 October 2011 - 04:28 PM.






#2 Herb191

Herb191

    Adventurer

  • Active Members
  • PipPip
  • 141 posts

Posted 27 October 2011 - 10:06 PM

I found some errors in my code so I changed the function so that it would work right.

AutoIt         
#include <IE.au3> ;This page currently has displays a popup when you try to navigate away from the page $any_url = "<a href='http://aquaponics4you.com/' class='bbc_url' title='External link' rel='nofollow external'>http://aquaponics4you.com/"</a> ;$any_url = "<a href='http://www.yahoo.com/' class='bbc_url' title='External link' rel='nofollow external'>http://www.yahoo.com/"</a> $oIE = _IECreate($any_url) $oIE = _IENavigate_kill_popup($oIE, "<a href='http://www.google.com/' class='bbc_url' title='External link' rel='nofollow external'>http://www.google.com/"</a>) Func _IENavigate_kill_popup($IEObject, $URL, $visible = 1)     If Not IsObj($IEObject) Then Return SetError(1, 0, 0)     $closed_process = False     $list_of_windows = WinList()     ;Trys to navigate to URL     _IENavigate($IEObject, $URL, 0)     _IELoadWait($IEObject, 0, 5000)     If _IEPropertyGet($IEObject, "locationurl") <> $URL Then         $closed_process = True         $hwnd = _IEPropertyGet($IEObject, "hwnd")         Do ;will loop until the IE window can close             If WinClose($hwnd) = 1 And WinExists($hwnd) = 1 Then                 $list_of_windows2 = WinList()                 For $i = 1 To $list_of_windows2[0][0]                     For $i2 = 1 To $list_of_windows[0][0]                         $win_existed_before = False                         If $list_of_windows2[$i][1] = $list_of_windows[$i2][1] Then                             $win_existed_before = True                             ExitLoop                         EndIf                     Next                     ;if the window did not exist before it will close it                     If $win_existed_before = False Then WinClose($list_of_windows2[$i][1])                 Next             EndIf         Until WinClose($hwnd) = 0     EndIf     ;will create a new IE object if old IE object made popups.     If $closed_process = True Then         $IEObject = _IECreate($URL, 0)         Return $IEObject     Else         _IELoadWait($IEObject)         Return $IEObject     EndIf EndFunc   ;==>_IENavigate_kill_popup





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users