SetCallback (Method)

From Legacy Roblox Wiki
Jump to navigationJump to search
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)