Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/samples/browser_dom.js
32278 views
#// Usage: jjs -fx browser_dom.js12/*3* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* - Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* - Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* - Neither the name of Oracle nor the names of its17* contributors may be used to endorse or promote products derived18* from this software without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS21* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,22* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR23* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR24* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,25* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233if (!$OPTIONS._fx) {34print("Usage: jjs -fx browser_dom.js");35exit(1);36}3738// JavaFX classes used39var ChangeListener = Java.type("javafx.beans.value.ChangeListener");40var Scene = Java.type("javafx.scene.Scene");41var WebView = Java.type("javafx.scene.web.WebView");4243// JavaFX start method44function start(stage) {45start.title = "Web View";46var wv = new WebView();47wv.engine.loadContent(<<EOF48<html>49<head>50<title>51This is the title52</title>53<script>54// click count for OK button55var okCount = 0;56</script>57</head>58<body>59Button from the input html<br>60<button type="button" onclick="okCount++">OK</button><br>61</body>62</html>63EOF, "text/html");6465// attach onload handler66wv.engine.loadWorker.stateProperty().addListener(67new ChangeListener() {68changed: function() {69// DOM document element70var document = wv.engine.document;71// DOM manipulation72var btn = document.createElement("button");73var n = 0;74// attach a button handler - nashorn function!75btn.onclick = function() {76n++; print("You clicked " + n + " time(s)");77print("you clicked OK " + wv.engine.executeScript("okCount"));78};79// attach text to button80var t = document.createTextNode("Click Me!");81btn.appendChild(t);82// attach button to the document83document.body.appendChild(btn);84}85}86);87stage.scene = new Scene(wv, 750, 500);88stage.show();89}909192