Search code examples
webgodot

How to redirect to a website in Godot Web


I'm planning on trying to see if it's possible to make a website in Godot(Yes, I know I shouldn't I just want to try just to try). I thinking about and looking over the features I need and I have one problem.

I just need a way for a person to press a button and get redirected to my itch games. I don't care if it creates a new tab or changes the current tab. Thank you for any help.


Solution

  • If you dont export to web you can call

    OS.shell_open("url")

    Sadly this does not work in an html export. A solution I found for myself is the JavaScript Interface. As the name suggested it allows you to execute Javascript.

    So to open a URL you could connect the pressed signal of a button to something like this:

    if OS.has_feature('JavaScript'):
        JavaScript.eval("""
            window.open('https://google.com', '_blank').focus();
        """)
    

    This will open a new tab in the active browser.

    I also found an article on the godot site, basically asking the same question (https://godotengine.org/qa/46978/how-do-i-open-richtextlabel-bbcode-links-in-an-html5-export). Here they tried to use an RichTextLabel with BBCode.

    The solution did not work for me, when I tested it, though.