Skip to content
thomthom edited this page Apr 5, 2013 · 1 revision

On Windows, the HTML document appear to be created when you call webdialog.show. If you attach an event to window.onload which send a command back to ruby to print "Hello World" in the console you'll see "Hello World" printed as you call .show. But on OSX it seems that the HTML document is created as you use .set_file or .set_html - before calling .show.

Example script:

module TT_Test
  @d = nil
  @d = UI::WebDialog.new('On Load Test')
  @d.add_action_callback('onload') { |dialog, params|
    puts '>> window.onload'
  }
  @d.set_html('Onload Test')
  def self.onload
    @d.show {
      puts '>> ruby block'
    }
  end
end

On Windows, when you run the script:

load 'test/webdialog.rb'
true
TT_Test.onload
true
>> ruby block
>> window.onload

Notice that the ruby block executes before the WebDialog onload event, which might indicate the block is run before the HTML document is ready.

On OSX:

> load 'test/webdialog.rb'
true
>> window.onload
> TT_Test.onload
true

Notice that window.onload triggers immediately as we've added the HTML to the WebDialog object. And that the .show block never executes.

So if you create a WebDialog object when you load your plugin, beware that it will consume resources from the moment you add the HTML and not wait for the dialog to actually show.