Create a link with a WebCanvas

To create link with a webCanvas, like you would in regular HTML with an image, and on top of it open it in a new window, here is what to place in a WebCanvas Shown event :

dim js as string js = js + "var ctrl = document.getElementById('"+me.controlid+"');" js = js + "var link = document.createElement('a'); link.setAttribute('href', '');" // Here is the target of the link js = js + "link.setAttribute('target', '_blank');" // Comment this line to open in current window js = js + "ctrl.appendChild(link); link.appendChild(ctrl.getElementsByTagName('canvas')[0]);" self.ExecuteJavaScript(js)

Note that links are the only way to reliably open a new window/tab, since popup blockers will block all methods that are not the direct result of a user click (including JavaScript Open). Not even showURL placed in MouseUp or MouseDown will work. Since all current browsers come with popup blocked as default, it is wise to use links, and not ask users to turn off their popup blocker.

Created and tested under 2017R1.

Works great

Thank You Michel

You’re welcome, Brian.

Why would you not use the Link control that’s in the Web Framework?

Because someone did not want text. The link control works only when there is text inside.

Ah okay, I missed that :slight_smile: