Webview:restorehost(hostname) method
Restore a previously mapped virtual host name (the previously mapped local folder won't be used anymore).
Parameters
hostname
A string representing the virtual host name that have been previously mapped with a call to Webview:hostfromfolder().
Return value
This function returnstrue
if the operation was successful or false
otherwise.
Example
local html = [[
<!DOCTYPE html>
<html>
<body>
<center style="margin-top:35%"><a href="https://www.google.com/]]..sys.File(arg[0]).name..[[">https://www.google.com/]]..sys.File(arg[1]).name..[[</a></center></a></center>
</body>
</html>]]
local ui = require "ui"
require "webview"
-- create a simple Webview
local win = ui.Window("Webview:restorehost() sample", 640, 480)
local Webview = ui.Webview(win, 0, 50, 640, 412)
local button = ui.Button(win, "Map virtual host 'www.google.com' to '"..sys.File(arg[0]).path.."'")
button:center()
button.y = 10
local mapped = false
win:status("Using real 'www.google.com' real hostname")
function button:onClick()
button.text = mapped and "Restore virtual host 'www.google.com'" or "Map virtual host 'www.google.com' to '"..sys.File(arg[0]).path.."'"
button:center()
button.y = 10
if mapped then
win:status("Host name 'www.google.com' have been restored")
Webview:restorehost("www.google.com")
else
Webview:hostfromfolder("www.google.com", sys.File(arg[0]).path)
win:status("Host name 'www.google.com' mapped to local '"..sys.File(arg[0]).path.."' folder")
Webview:loadstring(html)
end
mapped = not mapped
end
-- once ready, map www.google.com to the current local folder
-- and load the html content from string
function Webview:onReady()
Webview:loadstring(html)
end
-- update the user interface until the user closes the Window
ui.run(win):wait()