Hello…
I´m trying to manipulate the DOM directly through JRubyFX, but I´m not
getting it right. Here is my code (which is basically what I found on
JRubyFX wiki):
require ‘jrubyfx’
class HelloWorldApp < JRubyFX::Application
def start(stage)
browser = WebView.new
web_engine = browser.getEngine()
# get the window
window = web_engine.executeScript("window")
# get the HTMLDocument
document = window.eval("document")
// Loads a very simple HTML file that just shows the words 'hello
world’
f = Java::JavaIo.File.new(“simple.html”)
fil = f.toURI().toURL().toString()
web_engine.load(fil)
web_engine.setJavaScriptEnabled(true)
elmts = document.body.getElementsByTagName("*")
p elmts // #<Java::ComSunWebkitDom::NodeListImpl:0x1cf5189>
p elmts.getLength() // 0: no elements
elm = document.getElementsByClassName("body")
p elm.getLength() // 0: no body
para = document.createElement("p")
node = document.createTextNode("This is new")
para.appendChild(node)
elmts = document.body.getElementsByTagName("*")
p elmts // #<Java::ComSunWebkitDom::NodeListImpl:0x11d2018>
p elmts.getLength() // still prints 0
with(stage, title: "Hello World!", width: 800, height: 600) do
layout_scene do
browser // opens a browser windows with a string
end
end
stage.show # Tip: most of the time, () can be removed from method
calls
end
end
HelloWorldApp.launch
Any hint is appreciated!
Thanks,