Short answer, add this to the html file, right before the </body> tag:
<script>
setup(0,0)
</script>
Have a look at the totd.rb file in the Tools directory. It's a good example of a WebDialog.
Here's my re-write. Saving values between sessions can be done using Sketchup.write_default and Sketchup.read_default.
require "sketchup.rb"
#class JS_Test
# Inherit from the WebDialog. There's no need to use a Tool/
class JS_Test < UI;;WebDialog
#def activate # activate is a method of the Tool class.
def initialize
# dialog = UI;;WebDialog.new("test", true,"test", 320, 160, 1100, 60, true)
# super called the parant class "new"
super "test", true,"test", 320, 160, 1100, 60, true
fn= File.dirname(__FILE__)+'/test.html'
#dialog.set_file fn
set_file fn
#dialog.show {} #show it
show {} #show it
posX = "1"
#dialog.add_action_callback("setup") {|d,p|
add_action_callback("setup") { |d, p|
d.execute_script("document.getElementById('posX').value='#{posX}'")
}
#end # activate
end # initialize
end #class jsTest
if(not file_loaded?("test.rb"))
plugins_menu = UI.menu("Plugins")
#plugins_menu.add_item("test") { Sketchup.active_model.select_tool JS_Test.new }
plugins_menu.add_item("test") { JS_Test.new }
file_loaded("test.rb")
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="test" content="test" />
<title>test</title>
<script>
function setup(id,value)
{
window.location = 'skp;setup@'+document.getElementById('posX').value;
}
</script>
</head>
<body bgcolor="#e0dfe3">
<input type="text" size="8" id="posX" value="0"></div>
<script>setup();</script>
</body>
</html>