Open URL in Browser from inside the game

Hello Community
In my loadingscreen i want the people to be able to click the button and to open the link in there browser:

a href=“https://notmyrealurl.com/” target="_blank" rel=“noopener noreferrer” class=“button”

But i cant get it to open in a new browser enviroment. How to embed the URL so that people can click the link ingame and then it opens in there browser?

Help very much appreciated!

From javascript

window.invokeNative('openUrl', url);
1 Like

Ive embeded the code you send, but it aint working. What am I doing wrong?

            <a href="https://notmyrealurl.com/" target="_blank"  rel="noopener noreferrer" class="button"> Joine jetzt unserem Discord </a>
            <script> window.invokeNative('openUrl', url); </script>
3 Likes

Can you please take a look in the comment ive send below?

1 Like

It was an example, to make your link work you need to call that function on click e.g.

<a onclick="window.invokeNative('openUrl', 'https://notmyrealurl.com/')">Join my fancy discord!</a>

You could also add something like this

document.querySelectorAll('a').forEach(element => {
	element.addEventListener('click', e => {
		e.preventDefault()

		window.invokeNative('openUrl', e.target.href)
	})
})

This will add a “click” event to all links on your page and open them with openUrl so you wouldn’t need to change your <a>

5 Likes

Found a solution to this? Does not work for me. Tried this method with ion icons to open a URL during loading screen. Icons are clickable with custom cursor showing, except icons don’t take me to URL when clicked.

<a href="https://notmyurl.de/" target="_blank"  rel="noopener noreferrer" class="button" onclick="window.invokeNative('openUrl', 'https://notmyurl.de/');"> Joinour Discord now </a>
1 Like

Thank you, have been looking for a solution to add a link that can open during loading screen via ion icons. Will test this here shortly when at PC.

I would love to know if this works so i can use it in future scripts. It should work i guess.

FiveM is back up. Will be testing now and post results when done.

Doesn’t seem to work for me. Not sure if the icons are my issue or if my JS is wrote incorrect. Mind sharing what you have for the JS?

1 Like

Try this code:
<a href="https://discord.gg/yourdiscord" class="icon brands fa-discord" target="_blank" onclick="window.invokeNative('openUrl', 'https://discord.gg/yourdiscord');"><span class="label">Discord</span></a> its working for me.

1 Like