# SBrowserSurface

**Membres** 14

|           |                                       |                                                                                   |
| --------- | ------------------------------------- | --------------------------------------------------------------------------------- |
| Fonction  | [SetURL](#seturl)                     | Sets the URL for the browser frame, and navigates to it.                          |
| Fonction  | [Back](#back)                         | Equivalent to hitting the 'back' button within the browser.                       |
| Fonction  | [Forward](#forward)                   | Equivalent to hitting the 'forward' button within the browser.                    |
| Fonction  | [Reload](#reload)                     | Refreshes and reloads the current webpage.                                        |
| Fonction  | [RegisterFunction](#registerfunction) | Allows a JavaScript function that exists in the browser to be called by our code. |
| Fonction  | [CallFunction](#callfunction)         | Calls a JS function in the browser with a single argument.                        |
| Fonction  | [OnURLChanged](#onurlchanged)         | Binds a function to be called whenever the URL of the Browser Surface changes     |
| Propriété | [Networked](#networked)               | Should changes to this browser be streamed to other clients within the area?.     |
| Propriété | [Muted](#muted)                       | Whether this Browser Surface is muted or not.                                     |
| Propriété | [CanGoBack](#cangoback)               | Returns whether this Browser Surface can navigate back                            |
| Propriété | [CanGoForward](#cangoforward)         | Returns whether this Browser Surface can navigate forward                         |
| Propriété | [EnableInput](#enableinput)           | Whether this Browser Surface has Input enabled or not (interactable)              |
| Propriété | [Zoom](#zoom)                         | Set the Zoom of the browser surface (Pixel Scaling).                              |
| Propriété | [GameObject](#gameobject)             | Returns a reference to the GameObject of this component.                          |

## Fonctions

### SetURL

void SetURL(string url)

Sets the URL for the browser frame, and navigates to it.

Paramètres

| Paramètre | Type   | Description                                                               |
| --------- | ------ | ------------------------------------------------------------------------- |
| url       | string | A standard URL recognized by Chromium, such as <https://www.youtube.com>. |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.SetURL('https://www.youtube.com')

```

**Lua**

```lua
--the below scipt makes this object set Browser URL according to what's written in text field
--(Example: Set URL button)
--[Required: This object needs a Browser and InputField objects to be added as reference to references section in Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
webBrowser = Space.Host.GetReference("Browser")
urlField = Space.Host.GetReference("URL Field")

OnClick = function()

webBrowser.Browser.SetURL(urlField.UIInputField.Text)

end

urlField.UIInputField.Text = "https://www.youtube.com"
thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to set URL"
thisGameObject.Clickable.OnClick(OnClick)  

```

### Back

void Back()

Equivalent to hitting the 'back' button within the browser.

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.Back()

```

**Lua**

```lua
--the below scipt makes this object a clickable that navigates Back
--(Example: Browser navigation )
--[Required: Browser surface object needs to be added as a reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
browser = Space.Host.GetReference("Browser Surface Object").Browser

OnClick = function()
browser.Back()
end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to Enable/Disable browser Input"
thisGameObject.Clickable.OnClick(OnClick)

```

### Forward

void Forward()

Equivalent to hitting the 'forward' button within the browser.

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.Forward()

```

**Lua**

```lua
--the below scipt makes this object a clickable that navigates Forward
--(Example: Browser navigation )
--[Required: Browser surface object needs to be added as a reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
browser = Space.Host.GetReference("Browser Surface Object").Browser

OnClick = function()
browser.Forward()
end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to Enable/Disable browser Input"
thisGameObject.Clickable.OnClick(OnClick)

```

### Reload

void Reload()

Refreshes and reloads the current webpage.

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.Reload()

```

**Lua**

```lua
 --the below scipt makes this object a clickable that reloads the page
--(Example: Browser navigation )
--[Required: Browser surface object needs to be added as a reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
browser = Space.Host.GetReference("Browser Surface Object").Browser

OnClick = function()
browser.Reload()
end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to Enable/Disable browser Input"
thisGameObject.Clickable.OnClick(OnClick) 

```

### RegisterFunction

void RegisterFunction(string name, Closure function)

Allows a JavaScript function that exists in the browser to be called by our code.

Paramètres

| Paramètre | Type   | Description                                                                                                       |
| --------- | ------ | ----------------------------------------------------------------------------------------------------------------- |
| name      | string | The name of the JavaScript function we want to register. The function name should start with "**sinespace\_\_".** |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.RegisterFunction("sinespace__TestFunction", )

```

### CallFunction

void CallFunction(string name, string argument)

Calls a JS function in the browser with a single argument. The function name must begin with the characters "sinespace\_".

Paramètres

| Nom      | Type   | Valeur par défaut |
| -------- | ------ | ----------------- |
| name     | string | –                 |
| argument | string | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.CallFunction()

```

### OnURLChanged

void OnURLChanged(Closure e)

Binds a function to be called whenever the URL of the Browser Surface changes

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.OnURLChanged(aFunction)

```

**Lua**

```lua
--the below scipt makes this object clear the an InputField whenever URL changes
--(Example: URL Bar)
--[Required: This object needs a Browser and InputField objects to be added as reference to references section in Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
webBrowser = Space.Host.GetReference("Browser")
urlField = Space.Host.GetReference("URL Field")

OnURLChanged  ()

urlField.UIInputField.Text = " "

end

webBrowser.Browser.OnURLChanged(OnURLChanged)

```

## Propriétés

### Networked

bool Networked {get; set; }

Should changes to this browser be streamed to other clients within the area?.

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.Networked = true

```

**Lua**

```lua
 --the below scipt makes this object toggle Networking on it's parent browser
--(Example: browser controls)
--[Required: This object needs its parent to have the browser component]

thisGameObject = Space.Host.ExecutingObject

OnClick = function()

  if thisGameObject.Parent.Browser.Networked then
   thisGameObject.Parent.Browser.Networked = false
    Space.Log("Browser will not be networked")
  else
    thisGameObject.Parent.Browser.Networked = true
    Space.Log("Browser will be networked")
  end

end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to toggle Networking on Browser"
thisGameObject.Clickable.OnClick(OnClick)   

```

### Muted

bool Muted {get; set; }

Whether this Browser Surface is muted or not.

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.Muted=true

```

**Lua**

```lua
--the below scipt makes this object a clickable that mutes/unmutes a browser surface
--(Example: Browser Mute button )
--[Required: This object's parent needs to be an object with BrowserSurface component in it]

thisGameObject = Space.Host.ExecutingObject


OnClick = function()

  if thisGameObject.Parent.Browser.Muted then
   thisGameObject.Parent.Browser.Muted = false
    Space.Log("Browser unmuted")
  else
    thisGameObject.Parent.Browser.Muted = true
    Space.Log("Browser muted")
  end

end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to Mute/Unmute Browser"
thisGameObject.Clickable.OnClick(OnClick)  

```

### CanGoBack

bool CanGoBack {get; }

Returns whether this Browser Surface can navigate back

Exemple

**Lua**

```lua
CanGoBack = Space.Host.ExecutingObject.Browser.CanGoBack

```

**Lua**

```lua
 --the below scipt makes this Browser object show/hide it's Forward and Back
--buttons according to wether the actions are possible or not
--(Example: browser navigation )
--[Required: This object needs the forward and back objects added to the references section in scripting runtime]

thisGameObject = Space.Host.ExecutingObject
forwardButton = Space.Host.GetReference("Forward Button")
backButton = Space.Host.GetReference("Back Button")

OnUpdate = function()
 
 if thisGameObject.Browser.CanGoBack then
   backButton.Active = true
  else backButton.Active = false
end

if thisGameObject.Browser.CanGoForward then
  forwardButton.Active = true
else forwardButton.Active = false
end

  
end

thisGameObject.OnUpdate(OnUpdate)

```

### CanGoForward

bool CanGoForward {get; }

Returns whether this Browser Surface can navigate forward

Exemple

**Lua**

```lua
CanGoForward = Space.Host.ExecutingObject.Browser.CanGoForward

```

**Lua**

```lua
 --the below scipt makes this Browser object show/hide it's Forward and Back
--buttons according to wether the actions are possible or not
--(Example: browser navigation )
--[Required: This object needs the forward and back objects added to the references section in scripting runtime]

thisGameObject = Space.Host.ExecutingObject
forwardButton = Space.Host.GetReference("Forward Button")
backButton = Space.Host.GetReference("Back Button")

OnUpdate = function()
 
 if thisGameObject.Browser.CanGoBack then
   backButton.Active = true
  else backButton.Active = false
end

if thisGameObject.Browser.CanGoForward then
  forwardButton.Active = true
else forwardButton.Active = false
end

  
end

thisGameObject.OnUpdate(OnUpdate)

```

### EnableInput

bool EnableInput {get; set; }

Whether this Browser Surface has Input enabled or not (interactable)

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.EnableInput = false

```

**Lua**

```lua
--the below scipt makes this object a clickable that toggle Enable Input a browser surface
--(Example: Brower Enable Input toggle button )
--[Required: Browser surface object needs to be added as a reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
browser = Space.Host.GetReference("Browser Surface Object").Browser

OnClick = function()

  if browser.EnableInput then
   browser.EnableInput = false
    Space.Log("Browser input disabled")
  else
    browser.EnableInput = true
    Space.Log("Browser input enabled")
  end

end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to Enable/Disable browser Input"
thisGameObject.Clickable.OnClick(OnClick)

```

### Zoom

float Zoom {get; set; }

Set the Zoom of the browser surface (Pixel Scaling). Positive values zoom in, negative values zoom out.

Exemple

**Lua**

```lua
Space.Host.ExecutingObject.Browser.Zoom = 2

```

**Lua**

```lua
--the below scipt make a slider control the zoom in of a browser surface
--(Example: browser zoom controls)
--[Required: This object needs a Browser and slider objects to be added as reference to references section in Scripting Runtime component]
slider = Space.Host.GetReference("Slider").UISlider
browser = Space.Host.GetReference("Browser")

browser.Browser.SetURL("https://www.yahoo.com")


OnValueChanged = function()
browser.Browser.Zoom = slider.NormalizedValue * 5
end

slider.OnValueChanged(OnValueChanged)

```

### GameObject

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) GameObject {get; }

Returns a reference to the GameObject of this component.

Exemple

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.Browser.GameObject

```
