Link as Text element

When the user clicks on the text element, I need to open up a new website
The problem is I can’t do this with HTML/CSS elements, It has to be text from PlayCanvas
Is there any way to do that?

I tried this code, but it’s not working :slight_smile:

Hi @Dava,

Your code is correct, you just need to add it as a response to a click or touch handler. On a script that is attached to your element entity, and make sure you have Use Input enabled in the element component:

this.entity.element.on('mouseup', function(){
   var win = window.open('https://www.playcanvas.com', '_blank');
   win.focus();
}, this);

The problem is, it only adds URL on playcanvas existing URL, like in the picture

Grabbed one of the UI samples to give it a try, seems to be working fine. Check it here:

https://playcanvas.com/editor/scene/1042178

1 Like

It is not working anymore

I faced the same problem, but found a solution here: https://stackoverflow.com/questions/23373990/window-open-simply-adds-the-url-to-my-current-url

The problem is, that e.g. “www.google.com” is interpreted as a relative url and therefore appended to the current url. When using “https://www.google.com” it works as expected.

2 Likes