Sign in to follow this  
Followers 0
Cavaleri

Internet Explorer blocks pop-up by default [_IELinkClickByText]

9 posts in this topic

Hi guys,

I have been using this forum a lot to get help whenever I got stuck. Most of my issues turned out to be common problems and I was able to find a solution either through google or the search function in this forum.

However, I have come to a problem which I was unable to find any working solution to.

The scenario goes as follows:

I have a small script which opens IE to a website.

On this website it will click a link using the _IELinkClickByText function.

After this I will attach the new window to $oIE1

The problem is that popup windows are blocked by default from IE(At least when they go from one security level to another)

Stripped down to the basics, my script looks something like this:

#include <IE.au3>

Local $oIE = _IECreate("http://Mywebsite.com", 0, 1, 1, 1)
_IELoadWait($oIE)

_IELinkClickByText($oIE, "TextToRecognizeLink")
Local $oIE1 = _IEAttach("http://New.Link", "URL")
_IELoadWait($oIE1)

Now, this script works perfectly when I change my settings in IE to allow all popups.

However, this program will need to be run on various computers and all might not have disabled the popupblocker.

I have already searched for hours and found a couple of solutions, but none of them turned out to work.

One of the ideas was to send the CTRL command to IE while clicking the link.

It turns out that while holding CTRL when you click a link, it automatically allows the popup.

The script will now look like this:

#include <IE.au3>

Local $oIE = _IECreate("http://Mywebsite.com", 0, 1, 1, 1)
_IELoadWait($oIE)

Send("{CTRLDOWN}")
_IELinkClickByText($oIE, "TextToRecognizeLink")
Send("{CTRLUP}")
Local $oIE1 = _IEAttach("http://New.Link", "URL")
_IELoadWait($oIE1)

Now this doesn't work either. I tried using ControlSend aswell but I had no luck.

Then I tried to run the script as it was earlier, but manually pressing down CTRL while it was supposed to click the link.

It looks like _IELinkClickByText doesn't recognize CTRL being pushed down?

Can anyone help me with this issue? I can't be the only person who has been facing this difficulty.

Thank you for reading my thread.

Share this post


Link to post
Share on other sites



So you're able to attach to the new window by URL...why not just create your own new window using that URL?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

So you're able to attach to the new window by URL...why not just create your own new window using that URL?

Oh yea I should probably have removed that bit aswell. I will edit it now.

I am only able to attach the new window when it actually opens. I think that I will be using _IEPropertyGet($oIE1,"locationurl") to get the URL on the new site, but I will decide on that once I have overcome this problem.

The main problem is, that IE by default blocks popup. The innertext which is associated with the link that should be clicked with _IELinkClickByText might change from time to time, but the text stays the same. That's the reason why I chose to do it in this way instead of using _IECreate("mywebsite").

One solution I can think of will be a lot of mess, and leave space for a lot of errors:

It would be possible to automate the entire process of changing settings, but then I would need to make a code for every different version of IE since it is done in different ways in each edition. So I was hoping that there might be a better solution.

EDIT: Oh I wasn't able to edit my original post.

Edited by Cavaleri

Share this post


Link to post
Share on other sites

I though IE would fire an event when a pop-up was blocked, then return different things about the pop-up such as intended URL, size of the window, etc...but I found no such event.

Another thought is to get a collection of links, loop through them and when you find a match between the text you're looking for and the link's href then return the href then use that to create a new IE window. Here's an example (note that it uses the first occurrence of the text):

#include <IE.au3>
Local $oIE = _IE_Example("basic")
$textToMatch = "AutoIt"
$URL = _GetLinkURLByText($oIE, $textToMatch)
If $URL Then $oIE2 = _IECreate($URL)
Func _GetLinkURLByText(ByRef $o_object, $stringMatch)
Local $oLinks = _IELinkGetCollection($oIE), $sURL = 0, $sOuterText
For $oLink In $oLinks
  $sOuterText = $oLink.outerText
  If StringCompare($stringMatch, $sOuterText) = 0 Then
   ;Found a match
   $sURL = $oLink.href
   ExitLoop
  EndIf
Next
Return $sURL
EndFunc

Share this post


Link to post
Share on other sites

I though IE would fire an event when a pop-up was blocked, then return different things about the pop-up such as intended URL, size of the window, etc...but I found no such event.

Another thought is to get a collection of links, loop through them and when you find a match between the text you're looking for and the link's href then return the href then use that to create a new IE window. Here's an example (note that it uses the first occurrence of the text):

#include <IE.au3>
Local $oIE = _IE_Example("basic")
$textToMatch = "AutoIt"
$URL = _GetLinkURLByText($oIE, $textToMatch)
If $URL Then $oIE2 = _IECreate($URL)
Func _GetLinkURLByText(ByRef $o_object, $stringMatch)
Local $oLinks = _IELinkGetCollection($oIE), $sURL = 0, $sOuterText
For $oLink In $oLinks
$sOuterText = $oLink.outerText
If StringCompare($stringMatch, $sOuterText) = 0 Then
;Found a match
$sURL = $oLink.href
ExitLoop
EndIf
Next
Return $sURL
EndFunc

Ah yea this might actually be useful. I will look it over at least and see if I can do it this way. I found the same example inside the docs for _IELinkClickByText http://www.autoitscript.com/autoit3/docs/libfunctions/_IELinkClickByText.htm

But I ended up choosing the other strategy instead.

It would be most useful however, if it was possible to tweak the code to bypass that problem.

Is it possible to continue the script even though a 'while' function is running?

This idea came to my attention not too long ago:

Local $oIE = _IECreate("http://MyWebsite.com", 0, 1, 1, 1)
_IELoadWait($oIE)

;Dim $count
;While $count < 63
;Send('{CTRL}')
;Sleep(32)
;$count = $count + 1
;WEnd

_IELinkClickByText($oIE, "Recognizeable Text")

If you see what I meant to do, then if it was possible to continue the script while that 'while' function is still running, then it might be possible to catch the CTRL click.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I'm having trouble understanding what you're trying to do. Can you explain your project in full?

I don't really know what you mean by "other strategy" when you say you ended up choosing the other strategy instead.

I don't know what you're referring to when you say tweak the code to bypass that problem, what code? What problem?

As for the While loop, not sure what you're asking there either but the ExitLoop() command will get you out of a loop.

Sorry I'm just trying to help you solve your problem as you have posted it...

As for your original question I just thought you might be able to add the site as an allowed domain for pop-ups and those records are kept in the registry. Use Reg*() functions for that. This is not a great way to go though.

Edit: Nevermind I understand now what you're trying to do with the While loop. A new question, though: Why are you so focused on allowing the pop-up? What's in the pop-up that you can't get using the other method I gave you? This is where having the site code or a full explanation of what you're trying to do would be helpful.

Edited by MrMitchell

Share this post


Link to post
Share on other sites

I am sorry about the late response but there is a 3-post-limit for new members.

I appologize if I make myself hard to understand, but English is not my native language and I haven't learned the correct terminology for speaking about Autoit yet.

There is still time I hope :)

Back to the issue.

I have solved this myself. It was actually pretty easy.

All it took was a small change to the registry. It turns out that IE stores that info in the regkeys.

;Dim $sKey = 'HKCUSoftwareMicrosoftInternet ExplorerNew Windows'
;RegWrite($sKey, 'PopupMgr', 'REG_SZ', 'no')

Almost the same as you meant by the below quote, but I didn't only allow the domain I changed it to allow all sites.

Then I change it back when the program is done.

Quite simple to do once the idea popped up.

As for your original question I just thought you might be able to add the site as an allowed domain for pop-ups and those records are kept in the registry. Use Reg*() functions for that. This is not a great way to go though.

Share this post


Link to post
Share on other sites

Almost the same as you meant by the below quote, but I didn't only allow the domain I changed it to allow all sites.

Then I change it back when the program is done.

Quite simple to do once the idea popped up.

Yea that's what I meant...it's just that depending on who runs your script, they may not appreciate you changing pop-up settings, especially allowing all pop-ups.

Share this post


Link to post
Share on other sites

Yea that's what I meant...it's just that depending on who runs your script, they may not appreciate you changing pop-up settings, especially allowing all pop-ups.

Yes I realize this but it will be run on a local network mostly by employees.

But I have added the rewrite function at the end of my script to activate popups again for people, so they don't have to bother with that.

Now you made me consider making a function which checks if the popup was already disabled, so it won't enable it for users who doesn't want it enabled.

Hmm...(thinking)

Thank you for your time though, I am happy that for your quick responses :)

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