Utilizing Java Nashorn with WebEngine events

I'm having trouble processing events from a webEngine in Nashorn. Despite setting up the code to handle the "load" event, nothing is being printed or indicating that any events are triggering from the webEngine.

#!/usr/bin/jjs -fx
engine = (v=new(s=javafx.scene).web.WebView).engine
content_dir = __DIR__.replace('./','html/');
page = 'file://' + content_dir + 'index.html';
engine.onAction = function(){print("page loaded");};
engine.load(page);
$STAGE.scene=new s.Scene(v);

Although the page loads correctly, I am not receiving any events from the engine. I've looked into Java documentation for guidance, but it seems that in Nashorn only setting onAction should be sufficient. This situation has left me puzzled.

Answer №1

The WebView object's "engine" property is an instance of WebEngine in JavaFX. The WebEngine class does not contain a method named "setOnAction," only a method called setOnAlert which is triggered when the JavaScript engine in the WebView executes a JS alert call. Therefore, attempting to set the "onAction" property will be ineffective as it is not a valid property for a Java object. Instead, you should use the "loadWorker" state to monitor load events from the WebView's JavaScript engine.

To better understand how to interact between the WebView's JS engine and Nashorn JS engine, take a look at this sample code:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Populating an HTML form using a Node.js server

I am looking for a way to automate filling an HTML form's input fields, submitting it, and retrieving the body of the page. After some research, I came across a module called form-scraper. However, when I tried implementing it, I encountered the follo ...

vuejs mounted: Unable to assign a value to an undefined variable

When I try to run the function below upon mounted, I encounter an error: "Cannot set the property 'days' of undefined" Here is my code snippet: function getDays(date) { this.days = (new Date()).getTime() / ...

Ensure that the submission button also transmits an additional piece of information

My form has a submit button that sends field values to the address bar, but I want it to also add an extra value (&submitted=yes) when clicked. How can I modify my submit button from this: <input type="submit" name="submitted" value="submit"> ...

Utilizing server-side caching middleware with tRPC version 10

Currently, I am working on a Next.js project and exploring the possibility of incorporating in-memory caching for tRPC results. Each tRPC procedure should have the option to set a custom TTL for caching purposes. My initial thought is that utilizing tRPC&a ...

When the div is loaded, automatically navigate to the crucial li element within it, such as the one with the class "import

Welcome to my first webpage: <html> <head> <script type="text/javascript" src="js/jquery.min.js"></script> </head> <body> <div id="comment"></div> <script type="text/ja ...

What is the best way to compare the difference between the current date and a future date when dealing with dates in various languages?

My objective is to retrieve the current date and compare it with a specified date, which could be either the current date or a future date. The challenge arises from the fact that the format of the date string may vary based on the language setting of the ...

Is it possible for a Vue.js build to encounter errors due to unregistered components?

Exploring a component template... <template> <Unknown></Unknown> </template> In the context of this template, Unknown could be either a globally registered component or not. Upon encountering this scenario at runtime, an informa ...

Trigger an event, pause, and subsequently trigger another one within Vue

I have successfully emitted the following events to the parent component: this.$emit('sendToParent1', true); this.$emit('sendToParent2'); this.$emit('sendToParent3'); this.$emit('sendToParent4', true); this.$emit(&ap ...

The issue of integrating custom login functionality in SpringBoot with a REST api is causing problems for SpringSecurity

After attempting to create a custom login page and encountering issues with the functionality not working as expected, I am feeling confused about the SpringSecurity mechanism. It seems like the submit button is not doing anything when clicked. Below is th ...

Leveraging AngularJS html5mode in conjunction with express.js

Client-side: when("/page/:id", { templateUrl: "partials/note-tpl.html", controller : "AppPageController" }); $locationProvider.html5Mode( true ); Html: <a ng-href="/page/{{Page._id}}">{{Page.name}}</a> Server-side: app.use("/pag ...

Struggling to retrieve JSON data from within an array

[ { "May": [ { "year": 1994, "date": "2" }, { "Sequence": 2, "Type": "Images" } ], "_id": "1122" } ] The issue I am facing is retrieving the id except for the "date" f ...

Guide on using JSZip and VUE to handle an array of promises and store them in a local variable

My lack of experience with async functions has me feeling a bit lost right now... I'm attempting to loop through files in a folder within a zip file using JSZip, store these files in an array, sort them, and then save them to a local variable for furt ...

Run a script on an ajax requested page prior to the page being loaded

My website navigation utilizes AJAX for seamless transitions between pages. Specifically, I have two pages: index.html and profile.html. The structure of both pages is as follows: <html> <head> <script src="script1.js" type="text/javascript ...

Exploring recursive looping within a directory using Emscripten's File API

Is there a way to iterate through files in a folder using Emscripten? For example, I have created a folder called '/res' (FS.mkdir('/res')) and added some temporary files and subfolders inside it. How can I go about looping through th ...

What is the best way to incorporate a third-party element into Vue using a script tag?

I am in the process of developing a website and I would like to include a widget that links to a podcast on BuzzSprout. Initially, I created the site using HTML to test out different designs, but now I am looking to transition it to VueJS. In my HTML vers ...

Unable to find JSON data using the Javascript Kafka Magic Tool, as no results are being

In JSON format, I have a message that contains various details. My goal is to utilize Javascript search functionality to identify if the EmailAddress matches the specific value I am looking for within hundreds of similar messages: "Message": { ...

Tips for placing the header text at the center of a TemplateField in your design

I'm using a GridView with TemplateFields. I attempted to align the header text of the TemplateField to center by using HeaderStyle-HorizontalAlign="Center", but it doesn't seem to be working as expected. <asp:TemplateField HeaderTex ...

Transmitting Audio from Java Client to UDP Server

Seeking links, source codes, or tutorials on implementing a Java client to send audio to a server. The server will receive the audio file and play it through the computer speakers. Considering whether a UDP or TCP Server would be better for this scenario. ...

Inject data into an Angular 2 template

Does anybody know of a method to pass variables to templates in Angular2? Suppose I have the following code snippet: <div *ngFor="foo in foos"> <ng-container *ngTemplateOutlet="inner"</ng-container> </div> --------------- <n ...

Is there a way to switch the classList between various buttons using a single JavaScript function?

I'm currently developing a straightforward add to cart container that also has the ability to toggle between different product sizes. However, I am facing difficulties in achieving this functionality without having to create separate functions for ea ...