tornadofx入门19_webview

2019-12-27 10:26:26 浏览数 (1)

代码语言:javascript复制
import javafx.scene.web.WebView
import tornadofx.*

class MainView19 : View("WebView") {
    lateinit var wb: WebView
    override val root = borderpane {
        center = vbox(5) {
            webview {
                wb = this
                engine.isJavaScriptEnabled = true
                engine.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36n"
            }
        }
        top {
            hbox(10) {
                button("load dogedoge") {// 加载网址
                    action {
                        wb.engine.load("https:/www.dogedoge.com")
                    }
                }
                button("load local html") {// 加载本地html文件
                    action {
                        wb.engine.load(resources.url("/localHtml.html").toExternalForm())
                    }
                }
                button("load content") {// 加载html字符串
                    action {
                        wb.engine.loadContent("""<h1 style="color:blue">i am h1 content</h1>""")
                    }
                }
            }
        }

0 人点赞