Jump to content
Sign in to follow this  

_IELinkDownloadByText ?

Recommended Posts


Would it be possible to write a function similar to _IELinkClickByText, only have it save the file, simulating the "Save Link As" menu? The only reason I ask this? Unfortunately, in my particular case, INetGet will not work and neither will _IEAction("SaveAs").

I've searched through these forums and noted that IE has security against scripting downloading of files, but I wondered if anyone has had success (in AutoIt or otherwise) with the ExecWB command.

Here's what I started (i.e., copied/modified):

Func _IELinkDownloadByText(ByRef $o_object, $s_linkText, $i_index = 0, $f_wait = 1)
   If Not IsObj($o_object) Then
      __IEErrorNotify ("Error", "_IELinkClickByText", "$_IEStatus_InvalidDataType")
      SetError($_IEStatus_InvalidDataType, 1)
      Return 0
   Local $found = 0, $link, $linktext, $links = $o_object.document.Links
   $i_index = Number($i_index)
   For $link In $links
      $linktext = $link.OuterText & "" ; Append empty string to prevent problem with no outerText (image) links
      If $linktext = $s_linkText Then
         If ($found = $i_index) Then
            $o_object.ExecWB ("SaveAs", 1, $link, "")
            If $f_wait Then
               Return -1
            Return -1
         $found = $found + 1
   __IEErrorNotify ("Warning", "_IELinkClickByText", "$_IEStatus_NoMatch")
   SetError($_IEStatus_NoMatch) ; Could be caused by parameter 2, 3 or both
   Return 0


C:\...\Solix_Web.au3 (33) : ==> The requested action with this object has failed.: 
$o_object.ExecWB ("SaveAs", 1, $link, "") 
$o_object.ExecWB ("SaveAs", 1, $link, "")^ ERROR

I know my syntax on ExecWB is wrong, but I'm not clear how it's used, even after looking on MSDN and Googling other sites.

I'm thinking I'm at a dead end, but thought I'd ask, just in case anyone has any ideas.



Share this post

Link to post
Share on other sites

You are at a dead end with that approach. Been there, tried that.

_IEAction($oIE, "saveas") executes $oIE.document.execCommand("SaveAs"), which is in reality just an interface to ExecWB("saveAs") - the same command you are trying to use. This ExecWB("saveAs") actually has a documented parameter that is stated to allow saving without a file dialog, but it was disabled in IE a long time ago -- references you find to it are either very old or misguided. This feature was viewed as a security flaw (in all browsers) and I think you can see that if there was another way to do it through browser script it would certainly have been exploited and then fixed as well.

You can work around this with AutoIt however by activating the File SaveAs dialog and then using WinActivate and Send (or ControlSend) functions to automate the dialog.


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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