SetCallback (Method)

Revision as of 00:18, 30 October 2023 by Pongo02 (talk | contribs) (Created page with "<onlyinclude>{{Method|name = SetCallback |arguments = Function ''callback'' |description = Passes back variables from executed javascript code to lua. |object = HtmlWindow }}</onlyinclude> {{clear floats}} {{Example|Makes a window that will allow you to play audio from a textbox: <syntaxhighlight lang="lua"> html = game:service("HtmlService") wind = html:NewWindow() wind:Navigate() sound = workspace:FindFirstChild("HTMLSound") if not sound then sound = Instan...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
SetCallback( Function callback )
Returns nil
Description: Passes back variables from executed javascript code to lua.
Member of: HtmlWindow


Example
Makes a window that will allow you to play audio from a textbox:
html = game:service("HtmlService")

wind = html:NewWindow()
wind:Navigate()

sound = workspace:FindFirstChild("HTMLSound")
if not sound then
    sound = Instance.new("Sound",workspace)
    sound.Name = "HTMLSound"
end

function Call(ValueReturn,SoundID)
    print(ValueReturn,SoundID)
    if ValueReturn == "play" then
        sound.SoundId = SoundID
        sound:play()
    end
end

wind:Show()
wind.DocumentComplete:connect(function(url)
    wind:SetBody([==[
<input type="button" value="Play" onclick="var textbox=document.getElementById('IDTextbox'); window.external.Call('play',textbox.value)">
<input type="textbox" id="IDTextbox" value="http://c2.roblox.com/d2782423c9cb99cc1ee6ae0044b3273d">
]==])

wind:SetCallback(Call) end)