Open a Website in the browser from FiveM with a command

Hello Everybody :slight_smile:

So I don’t know too much about Javascript as I don’t really use anything outside of Lua and HTML and even then my knowledge is minimal since I’m not really a scripter but I’m trying to make something pretty basic and it needs to use javascript (so I’ve been told)

I want to be able to execute a command in game, that will then open a website on the players default browser

What I currently have is

RegisterCommand(“jrwebsite”, function open_url(){
window.open(“http://google.com”,“_blank”);
})

what would I need to do to actually make it work, I know that the 2nd line is the correct way to open it, just not sure about creating the function with a command that actually works since in lua it would be different. (I wish lua could do this)

anyway thanks guys any help will be appreciated.

2 Likes

You can’t use window.open or such in a client script, it must be in NUI.
In NUI do not use window.open but rather openUrl:

window.invokeNative("openUrl", url);
5 Likes

I actually got it thanks :slight_smile:
The Nui thing helped big time