Forum: JRuby DOM manipulation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B97f192e676f1a67e0ef18f022671406?d=identicon&s=25 Rodrigo Botafogo (Guest)
on 2015-05-08 19:50
(Received via mailing list)
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,
This topic is locked and can not be replied to.