Sign in to follow this  
Followers 0

Getting URL from active tab regardless of browser

6 posts in this topic

Hey fellas,

I'm looking for an easy way to get an URL from an active browser.

Now, I know about chrome and IE includes but the script I'm writing will be used by users with different browsers, obviously. I can imagine have both IE and Chrome includes in the script, identifying what browser the user uses etc but I was wondering if there is any other easier way.



Share this post

Link to post
Share on other sites

The only universal method I know is highlighting the address bar using F6 (when the browser is active). Since there is no control to get info from on any browsers

F6 or Alt+d will select and highlight the url in the address bar, then you can send Ctrl+c to copy it

1 person likes this

Share this post

Link to post
Share on other sites

That's fair enough! Just tried in Chrome and IE. Do you know if it works for other browsers?

Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

I'm using Firefox and it works, I've used it in Internet Explorer 11, 10, and in Chrome. I don't know about any other ones but those are the 3 most popular browsers. Download and try it on Safari. I don't know about Spartan (IE's replacement) but I'm assuming it will do the same, since it's Microsoft.

Edited by InunoTaishou

Share this post

Link to post
Share on other sites

Thanks again mate!

Share this post

Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • TheSaint
      By TheSaint
      I've finally come up with a simple solution for dragging & dropping a URL.
      It's not perfect, but it does the job. Mostly just a tweak of some Help file examples.
      Thanks also to AutoBert, for his StringRegExp and example that set me on the right path.
      I have seen this requested for many times, so enjoy!
      It goes without saying, that any improvements are welcome.
      Dropbox For URLs.au3
      #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Global $hGui, $g_hRichEdit Example() Func Example() Local $cnt, $URL, $val, $text Local $iMsg, $state = $WS_CAPTION + $WS_POPUP + $WS_CLIPSIBLINGS + $WS_SYSMENU $hGui = GUICreate(StringTrimRight(@ScriptName, 4), 160, 100, -1, -1, $state, $WS_EX_TOPMOST) $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 140, 80, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetEventMask($g_hRichEdit, $ENM_LINK) _GUICtrlRichEdit_AutoDetectURL($g_hRichEdit, True) $cnt = 0 While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ExitLoop Case Else If $cnt = 20 Then $text = _GUICtrlRichEdit_GetText($g_hRichEdit) If $text <> "" Then $val = StringRegExp($text, "(?s)((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)", 2) If UBound($val) > 0 Then $URL = $text ClipPut($URL) ;MsgBox(0, "URL", $URL, 0, $hGui) Else _GUICtrlRichEdit_SetText($g_hRichEdit, "Only URL's are supported!") ;MsgBox(0, "Not URL", "Only URL's are supported!", 0, $hGui) EndIf Sleep(600) _GUICtrlRichEdit_SetText($g_hRichEdit, "") EndIf $cnt = 0 Else $cnt = $cnt + 1 EndIf EndSelect WEnd EndFunc ;==>Example GUIDelete($hGui) Exit I also wanted a version that would work with an earlier version of AutoIt (v3.3.0.0), to use with updates for some older scripts (programs).
      The following works fine on my Win XP laptop, but fails (also when compiled) on my Win 7 Netbook.
      I found a RichEdit example in the GUICtrlCreateEdit function (Example 2) in the AutoIt v3.3.0.0 Help file, and modified that to suit my script.
      Failure is no doubt due to 'MSCOMCT2.OCX' missing from the System32 folder, at the very least.
      Any solution to getting the following to work on Win 7 would be greatly appreciated. Perhaps a different '.OCX' file etc.
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> Global $oMyError RichEditExample() Exit ; Rich edit control EXAMPLE using GUICtrlCreateObj ; Author: Kåre Johansson ; AutoIt Version: ; Description: Very Simple example: Embedding RICHTEXT object ; Needs: MSCOMCT2.OCX in system32 but it's probably already there ; Date: 3 jul 2005 Func RichEditExample() Local $cnt, $DropBoxGUI, $GUIActiveX, $msg, $oRP, $state, $text, $URL, $val $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $oRP = ObjCreate("RICHTEXT.RichtextCtrl.1") If @error Then Return $state = $WS_CAPTION + $WS_POPUP + $WS_CLIPSIBLINGS + $WS_SYSMENU $DropBoxGUI = GUICreate(StringTrimRight(@ScriptName, 4), 160, 100, -1, -1, $state, $WS_EX_TOPMOST) $GUIActiveX = GUICtrlCreateObj($oRP, 0, 0, 140, 80) GUICtrlSetPos($GUIActiveX, 5, 5, 150, 90) $cnt = 0 With $oRP; Object tag pool .OLEDrag() .Font = 'Arial' .Text = @CRLF & @CRLF & " Drag & Drop a URL here." .SelBold = True .BackColor = 0xff00 ;.FileName = @ScriptDir & '\RichText.rtf' ;$oRP.AboutBox() ;$oRP.SelBold = False ;$oRP.SelItalic = False ;$oRP.SelUnderline = False ;$oRP.SelFontSize = 8 ;$oRP.SaveFile(@ScriptDir & "\RichText.rtf", 0) EndWith GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($DropBoxGUI) ExitLoop Case Else If $cnt = 20 Then $text = $oRP.Text If $text <> "" Then If $text = @CRLF & @CRLF & " Drag & Drop a URL here." Then Sleep(2000) Else $val = StringRegExp($text, "(?s)((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)", 2) If UBound($val) > 0 Then $URL = $text ClipPut($URL) ;MsgBox(0, "URL", $URL, 0, $hGui) Sleep(600) Else With $oRP .Text = "Only URL's are supported!" EndWith ;MsgBox(0, "Not URL", "Only URL's are supported!", 0, $hGui) Sleep(1500) EndIf EndIf With $oRP .Text = "" .SelBold = False EndWith EndIf $cnt = 0 Else $cnt = $cnt + 1 EndIf EndSelect WEnd EndFunc ;==>RichEditExample Func MyErrFunc() MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext , 5) ; Will automatically continue after 5 seconds Local $err = $oMyError.number If $err = 0 Then $err = -1 SetError($err) ; to check for after this function returns EndFunc ;==>MyErrFunc And a slower embedded IE based version. This has an error in latest AutoIt, but works fine in v3.3.0.0.
      #include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> Local $DropboxGUI, $GUIActiveX, $loaded, $loops, $oBody, $oIE, $sHTML, $timeout, $urlpage _IEErrorHandlerRegister() $oIE = _IECreateEmbedded() $DropboxGUI = GUICreate("URL Dropbox", 140, 140, -1, -1, _ $WS_OVERLAPPED + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_SYSMENU, $WS_EX_TOPMOST) $GUIActiveX = GUICtrlCreateObj($oIE, 5, 5, 125, 100) $oBody = _IETagNameGetCollection($oIE, "body", 0) _IEDocInsertHTML($oBody, "", "afterbegin") $loaded = _IEPropertyGet($oIE, "locationurl") $urlpage = $loaded $loops = 0 $sHTML = "" $sHTML &= "<HTML>" & @CR $sHTML &= "<HEAD>" & @CR $sHTML &= "<TITLE>Drag And Drop Example</TITLE>" & @CR $sHTML &= "</HEAD>" & @CR $sHTML &= "<BODY>" & @CR $sHTML &= "</BODY>" & @CR $sHTML &= "</HTML>" _IELoadWaitTimeout(1) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ; Quit, Close or Exit window GUIDelete($DropboxGUI) ExitLoop Case Else ;;; If $loops = 10 Then $loops = 0 $loaded = _IEPropertyGet($oIE, "locationurl") If $loaded <> $urlpage Then _IEAction($oIE, "stop") _IEDocWriteHTML($oIE, $sHTML) If $loaded = "res://ieframe.dll/navcancl.htm" Then $loaded = "" $urlpage = $loaded _IEBodyWriteHTML($oIE, '<p style="WORD-WRAP: normal; WORD-BREAK: break-all; FONT-SIZE: 8px">' & $loaded & '</p>') EndIf Else $loops = $loops + 1 EndIf EndSelect WEnd Exit  
    • MAS
      By MAS
      I want to crack a URL by using the _WinHttpCrackUrl() function located in
      >winhttp UDF 
      It goes well for some URL's but for other URL's it gives error and sets the @error to 1
      the URL and my example
      #include "WinHttp.au3" #include <Array.au3> $url = "" $aUrl = _WinHttpCrackUrl($url) MsgBox(0, "Error", @error) _ArrayDisplay($aUrl, "_WinHttpCrackUrl()") if anyone can help in this thanks
    • remin
      By remin
      I created this little script:
      HotKeySet("!g", "searchgoogle") While 1     Sleep(10000) WEnd Func searchgoogle()    Sleep(500)    Send( "^c" )    Sleep(500)     $ClipB2 = ClipGet()     $url = "" & $ClipB2     Sleep(300)     MsgBox(0,"",$url) EndFunc I just select a word and invoke the hotkey.
      More than an hour I try to change the Sleep values but something still does not work:
      When I invoke the 1st time the hotkey, almost always it returns the correct url,
      but when I reuse the hotkey a few times it doesn't copy any more and the url
      is constructed with previous clipboard value.
      Does anyone know what is wrong in my script?
    • meisandy
      By meisandy
      Hi all,
      I'm using an embedded IE object to fill in a form and submit it. The form uses the POST method and has a Javascript function which runs when the form is submitted and changes some values according to what is entered into the form and generates a nonce, etc. When the form is submitted a file download is triggered.
      How could I deal with this because at the minute the file download dialog is appearing? The only way I can think of is to send a keypress when the file download window becomes active but I have seen that this is not reliable.
      Thanks in advance
    • Ascend4nt
      By Ascend4nt
      Internet Shortcut Sanitizer

      With the newest Firefox and IE browsers, there's a bit of an issue with Internet Shortcuts created, which have been traditionally saved in a .URL file on Windows (an INI-structured file).
      Firefox now adds Icon information to the file which points it at a location within %localappdata%MozillaProfiles.  This to me is annoying and unnecessary. While it may reflect the favicon of a website, its got a few problems:
      When the cache is cleared or the bookmark is moved to another computer or put on a fresh install, that icon isn't there anymore. These shortcuts contain your logon name (part of %localappdata%), so be aware of this if you are going to share them! (or just use a generic logon)  
      Here's the content of a typical Firefox .URL file (<LogonName> is your Windows logon):
      [InternetShortcut] URL= IDList= HotKey=0 IconFile=C:\Users\<LogonName>\AppData\Local\Mozilla\Firefox\Profiles\a3n21a.default\shortcutCache\md34sdyu7s_g==.ico IconIndex=0 _
      Update: if you have Firefox 21, you can follow and edit Firefox's about:config settings to fix the way URL shortcuts are created.
      Internet Explorer (IE 9+) now has its own new shortcut extension (.website), which seems to only work with the IE browser.  These files are basically 'enhanced' internet shortcuts. The extra information included is cryptic, and appears to be of no use outside of IE.  However, the INI-format is the same, and the [internetShortcut] section is the same, so it can simply be renamed to have a .URL extension.
      Here's the content of a typical Internet Explorer 9+ .website file:
      [{000214A0-0000-0000-C000-000000000046}] Prop4=31,Google Prop3=19,2 [{A7AF692E-098D-4C08-A225-D433CA835ED0}] Prop5=3,0 Prop9=19,0 [InternetShortcut] URL= IDList= IconFile= IconIndex=1 [{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}] Prop12=19,2 Prop5=8,Microsoft.Website.9CB8E698.8730F9E8 _
      (Note the embedded [internetShortcut] section)
      Sanitize your shortcuts!
      The fix for these problems?  A little Internet Shortcut Sanitizer program.  If you're like me and just want Internet Shortcuts to be just that - a simple file with a URL in it, then this program will give you what you need.  It strips everything out but the 2 lines necessary to work as a .URL file:
      [InternetShortcut] URL= _
      The script will also create .URL's from .website files and remove all the IE related stuff.  Currently it either takes 1 parameter or allows you to select 1 file to change.  However, it can be adapted to work on multiple files with a little extra effort.  However, I'd recommend something like grepWin to clear out folders (see 3rd post), and maybe a batch file renamer to deal with .website -> .URL conversion.
      Below is the script.
      - Packaged the main functionality of the script into the embedded UDF: _InternetShortcutSanitize()
      ; ================================================================================================================== ; <InternetShortcutSanitizer.au3> ; ; 'Sanitizes' Internet shortcuts, both of the traditional Windows .URL format and of the newer IE .website format ; In the case of the latter, it will delete the .website variant and create a URL version ; ; Author: Ascend4nt ; ================================================================================================================== Local $sFile If $CmdLine[0] < 1 Then $sFile=FileOpenDialog("Select Internet Shortcut to Sanitize","","Internet Shortcut Files (*.URL;*.website)|All Files (*.*)",3) If @error Or $sFile="" Then Exit Else $sFile = $CmdLine[1] EndIf $sFile = StringStripWS($sFile,3) If Not FileExists($sFile) Then Exit ;~ ConsoleWrite("Internet Shortcut file to sanitize = "&$sFile&@CRLF) _InternetShortcutSanitize($sFile) ; =================================================================================================== ; Func _InternetShortcutSanitize($sFile) ; ; 'Sanitizes' the Internet shortcut file passed. This keeps URL files to a 2-line file of this format: ; [InternetShortcut] ; URL= ; ; In the case the input file is an Internet Explorer .website shortcut (in IE 9+), it will ; create a .URL file of the same name, and upon successful write, it will delete the .website file. ; ; $sFile = Full path to file to sanitize ; ; Return: ; Success: True ; Failure: False with @error set ; ; Author: Ascend4nt ; =================================================================================================== Func _InternetShortcutSanitize($sFile) If $sFile = "" Then Return SetError(1,@error,False) ; Get rid of whitespace at beginning & end $sFile = StringStripWS($sFile,3) Local $sFileOut, $nRet Local $sURL = "", $sFileContent = "" $sURL = IniRead($sFile, "InternetShortcut", "URL", "") If @error Or $sURL = "" Then Return SetError(-1,@error,False) ;~ ConsoleWrite("URL = "&$sURL&@CRLF) ; Standard URL format $sFileContent = "[InternetShortcut]"&@CRLF&"URL="&$sURL&@CRLF ; $sFileOut: If not .website, we keep it the same. ; Otherwise, we transfer it to a .URL file If StringRight($sFile, 8) = ".website" Then $sFileOut = StringReplace($sFile, ".website", ".URL", -1) Else $sFileOut = $sFile EndIf ; Create/Overwrite the URL file $hFile = FileOpen($sFileOut, 2) If $hFile = -1 Then Return SetError(3, 0, False) $nRet = FileWrite($hFile, $sFileContent) FileClose($hFile) ; FileWrite error? If Not $nRet Then ;~ ConsoleWrite("File Write error"&@CRLF) Return SetError(4,0,False) EndIf ; .website -> .URL 'translation' performed? Delete .website file If $sFile <> $sFileOut Then ; Make sure we actually created the .URL file before delete: If FileExists($sFileOut) Then FileDelete($sFile) EndIf Return True EndFunc