Adding WebLink Capability to WebButton & WebImageView

Note: See the updated blog post for version 1.1.

In Real Studio WE if you want to open a URL in another tab or window, you have two options. You can use a WebLink with a target of New Window. Or you can execute some JavaScript in response to an event. Popup blockers will not block the WebLink because the user has to click it, but they will block the JavaScript even if it’s executed in response to a user click on a button or image. But what if you want to open a URL in a new window from those controls?

This question was recently asked on the forums, so I thought I would take a look and see if there was a way, and found one. Web Custom Controls 1.3 will include two functions, LinkAddTD and LinkChangeTD, which allow you to add a link to WebButton or WebImageView, and change the link later. You can control the target, which defaults to _blank and will open the URL in a new tab/window. Since this is a small bit of code and not central to nor dependent upon wcc, I’m also releasing these two functions as open source (click here to download).

There are a few catches:

  1. Once you’ve added a link the Action and DoubleClick events no longer fire. MouseDown still fires.
  2. Certain actions in MouseDown will prevent the link from opening. Showing a MsgBox is one. If your MouseDown code interferes with the link, try putting it in a WebTimer and starting the timer from MouseDown.
  3. This works in 2011r3 and 2011r4.3, but there are no guarantees it will continue to work in the future. Real Software may change the way they organize the HTML for these controls which would break this little hack. If you organize your UI around this functionality, be prepared to change it in the future.

Otherwise this seems to work fine in the tests I’ve performed. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *