Jump to content

Refresh URL address


 Share

Recommended Posts

I am trying to create a custom browser using IE. This is just a test, and I am trying to build some knowledge. I am having ahard time getting the URL to change in the Address bar I created.

I have tried various ways of writing the code. At present, the code I have constantly changes the URL as soon as I begin to type a new one. Does anyone have any ideas how to get the URL of the current website? I have put my code in a loop so it is constantly checking. I originally did it without a loop, but the URL then wouldn't change if I did a search with Google say.

Here is my code. If anyone has any suggestions, I'd appreciate the help.

; *******************************************************
; Example 1 - Trap COM errors so that 'Back' and 'Forward'
;               outside of history bounds does not abort script
;               (expect COM errors to be sent to the console)
; *******************************************************
;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

If Not FileExists("C:\temp\url.ini") Then
    IniWrite("C:\temp\url.ini","URL","URL","http://www.autoitscript.com")
EndIf
$urlHome = IniRead("C:\temp\url.ini","URL","URL","")
_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
$GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
$GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
$GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
$GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)
$GUI_Button_Go = GUICtrlCreateButton("Go", 450, 420, 100, 30)
$url = GUICtrlCreateInput($urlHome,10,10,600,25)
GUICtrlSetData($url,$urlHome)

GUISetState()       ;Show GUI

_IENavigate ($oIE, $urlHome)

; Waiting for user to close the window
While 1
    _inputChk()
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_Button_Home
            _IENavigate ($oIE, "http://www.autoitscript.com")
        Case $GUI_Button_Back
            _IEAction ($oIE, "back")
        Case $GUI_Button_Forward
            _IEAction ($oIE, "forward")
        Case $GUI_Button_Stop
            _IEAction ($oIE, "stop")
        Case $GUI_Button_Go
            $urlValue = GUICtrlRead($url)
            _IENavigate($oIE,$urlValue)
            $urlGet = _IEPropertyGet($oIE,"locationurl")
            GUICtrlSetData($url,$urlGet)
    EndSwitch
WEnd

GUIDelete()

Exit

Func _inputChk()
    $urlGet = _IEPropertyGet($oIE,"locationurl")
    FileWriteLine("C:\temp\Cache.txt",$urlGet)
    $URLGUI = GUICtrlRead($url)
    $URLCache = FileReadLine("C:\temp\Cache.txt",1)
    If $URLCache <> $URLGUI Then
        GUICtrlSetData($url,$urlGet)
    EndIf
    FileDelete("C:\temp\Cache.txt")
    Sleep(1000)
EndFunc

Thanks,

Jeff

Link to comment
Share on other sites

I am trying to create a custom browser using IE. This is just a test, and I am trying to build some knowledge. I am having ahard time getting the URL to change in the Address bar I created.

I have tried various ways of writing the code. At present, the code I have constantly changes the URL as soon as I begin to type a new one. Does anyone have any ideas how to get the URL of the current website? I have put my code in a loop so it is constantly checking. I originally did it without a loop, but the URL then wouldn't change if I did a search with Google say.

Here is my code. If anyone has any suggestions, I'd appreciate the help.

Thanks,

Jeff

I don't understand why you ask for getting the current url when you already have the solution Posted Image

_IEPropertyGet ( $oIE, "locationurl" ) is the right way.

You can simplify your adressbar update by this : Posted Image

Func _inputChk ( )
    $urlGet = _IEPropertyGet ( $oIE, "locationurl" )
    $URLGUI = GUICtrlRead ( $url )
    If $urlGet <> $URLGUI Then
        GUICtrlSetData ( $url, $urlGet )
    EndIf
    Sleep ( 1000 )
EndFunc

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Thanks for your response.

I know the way I had it setup was the best way to get the URL. The problem is I don't think I am refreshing the address properly when the URL changes.

I don't think I am making myself clear here...

The loop that constantly checks the URL is running so frequently that as soon as I start typing in a different address i.e. www.google.com, the Textbox that is my address bar resets the URL address back to the old address. It does this because I check to see if the URL in the textbox has changed from the current address.

I guess what I am looking for is a way for IE to check the URL it is be redirected too before it goes to the sites, and then populates that URL into the address bar.

The reason I added the URL to a text file is because without the text file, the address bar flashes like crazy trying to refresh the site.

Link to comment
Share on other sites

; *******************************************************
; Example 1 - Trap COM errors so that 'Back' and 'Forward'
;               outside of history bounds does not abort script
;               (expect COM errors to be sent to the console)
; *******************************************************
;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Global $old_url = ''

If Not FileExists("C:\temp\url.ini") Then
    IniWrite("C:\temp\url.ini","URL","URL","http://www.autoitscript.com")
EndIf
$urlHome = IniRead("C:\temp\url.ini","URL","URL","")
_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)
$GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
$GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
$GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
$GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)
$GUI_Button_Go = GUICtrlCreateButton("Go", 450, 420, 100, 30)
$url = GUICtrlCreateInput($urlHome,10,10,600,25)
GUICtrlSetData($url,$urlHome)

GUISetState()       ;Show GUI

_IENavigate ($oIE, $urlHome)

; Waiting for user to close the window
While 1
    _inputChk()
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_Button_Home
            _IENavigate ($oIE, "http://www.autoitscript.com")
        Case $GUI_Button_Back
            _IEAction ($oIE, "back")
        Case $GUI_Button_Forward
            _IEAction ($oIE, "forward")
        Case $GUI_Button_Stop
            _IEAction ($oIE, "stop")
        Case $GUI_Button_Go
            $urlValue = GUICtrlRead($url)
            _IENavigate($oIE,$urlValue)
            $urlGet = _IEPropertyGet($oIE,"locationurl")
            GUICtrlSetData($url,$urlGet)
    EndSwitch
WEnd

GUIDelete()

Exit

Func _inputChk()
    $current_url = _IEPropertyGet ($oIE, "locationurl")
    If $old_url <> $current_url Then
            $old_url = $current_url
        GUICtrlSetData($url, $current_url)
    EndIf
EndFunc

~Cake

Edited by Cake
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...