How do I open RichTextLabel BBCode links in an HTML5 export?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Serneum

I currently have a project that has a RichTextLabel that displays text. Some of the text we display has BBCode for URLs ([url=someUrl]Text[/url]) and then we have a script on the node containing the label:

func _on_text_meta_clicked(meta):
    OS.shell_open(meta)

The label has a connection to that method and it works wonderfully when we run the project directly from the Godot editor or from a runnable .dmg file on our Macs. I exported the project to HTML5, uploaded it to a server, and noticed that the links do not work. I’m assuming the issue is the reliance on OS, but would like to have this work in both cases. Is there another class I can use and a method I can call to check how the project is running to see if I should use OS or the other class at runtime?

:bust_in_silhouette: Reply From: ElectronicArmory

This worked for me:

func _ready():
	if OS.get_name() != "HTML5":
		$RichTextLabel.connect("meta_clicked", self, "_on_RichTextLabel_meta_clicked")

func _on_RichTextLabel_meta_clicked(meta):
	OS.shell_open(meta)

Basically, if it’s HTML let the browser handle the call (by doing nothing). If it’s not HTML, hook up the meta_click signal manually in the _ready function for any OS and make the OS call the url using the shell_open function.

This might be a year after you asked, but I was looking for the same thing and your question gave me the idea of using the meta_click function to solve my issue of running on the OS (so opposite of the issue you had).

So hopefully this helps someone else.