Having trouble with JavaFX script not functioning properly after switching between pages

After the user interacts with a certain element on the page and triggers a change, the functionality of JavaFX scripting stops working.

welcome.html

<div onclick="app.goodbye()">goodbye</div>

farewell.html

<div onclick="app.welcomeBack()">welcome back</div>

JavaApp.class

 public class JavaApp{

    public void welcomeBack(){
        //perform some tasks here
        setURL("/welcome.html");
    }

    public void goodbye(){
        //perform some tasks here
        setURL("/farewell.html");
    }

    private void setURL(final String uriString){
       Platform.runLater(new Runnable(){

            public void run(){
                JSObject win = (JSObject) webViewPanel.getWebEngine().executeScript("window");
                win.setMember("app",  new JavaApp());
                webViewPanel.loadURL(Browser.class.getResource(uriString).toExternalForm());
            }
        });
    }
}

What steps should be taken to resolve this issue?

Answer №1

The answer provided by Uluk Biy is accurate (however, I am unable to leave a comment as an answer). Make sure to give him a thumbs up if you found this information helpful.

Attempt to access the window object and set "app" after the webview's engine successfully loads the URL. Specifically when the engine is in State.SUCCEEDED state. Refer to WebEngine's javadoc for more information.

You can find the WebEngine API page at: http://docs.oracle.com/javafx/2/api/javafx/scene/web/WebEngine.html

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

Having trouble manipulating DOM elements in Node.js with JSDOM?

Feeling a bit lost here - I'm a newbie to Node JS and I'm attempting to manipulate a DOM element within index.js, my main Node.js file. After reading up on the jsdom module, which supposedly allows you to interact with HTML elements in Node, I t ...

Verify if a checkbox is selected upon loading the page

Hey there, I have a jQuery change function set up to turn an input text box grey and read-only when a user selects a checkbox. However, I'm interested in adding a check on page load to see if the checkbox is already selected. Any suggestions for enhan ...

Updating React state by changing the value of a specific key

I've been diving into React lately and I'm facing an issue with updating state values for a specific key. Below is my current state: this.state = { connections : { facebook : "http://facebook.com", flickr : null, ...

When a React Router link is activated, the React Bootstrap dropdown remains open instead of closing as expected

<NavDropdown className="userDropdownButton" title="dropdown" id="user-nav-dropdown" alignRight > <div className="userDropDown"> <Link to="/user" className="userDropDownheader"> user </Link> </div> < ...

What is the best way to make a fixed div appear when a user scrolls down the page, similar to Facebook

As I was scrolling down on Facebook, I noticed that the ads divs stay fixed when they reach the bottom. Has anyone figured out how to achieve this effect? I believe it can be done using a combination of JavaScript and CSS. Does anyone have the code for im ...

How to display a page outside the router-outlet in angular 4

I'm currently developing an angular 4 application and I am trying to figure out how to load the login.page.ts outside of the router-outlet This is what my home.component.html file looks like: <div class="container"> <top-nav-bar></ ...

Adjustable slider to display progress, with the ability to reach full completion and reset back

In my current project, I am working on a progress bar that is linked to XP and MAX XP values in SQL. Each time a button is clicked, the user receives 1 XP and the maximum XP is set at 10. Ideally, when a user reaches 100% XP, the progress bar should reset ...

Problem with Pinia: nested array in an object

My unique store located within a vue3 application, contains an object called currentReservation with a property named pricings which is an array. Each pricing includes an id and quantity. When I add a new pricing, it is added to both the store and compone ...

I'm looking to design a navbar similar to the one in the provided link, and I'd like it to appear when scrolling

I'm struggling to figure out how this particular navbar was created. How can I add a navlist for Videos and make the navbar visible upon scrolling? Are there any resources, articles, or hints to help me get started with this? LINK - ...

Tips for adjusting String indexes to commence at 1

Consider the following scenario: I have a string s = 'muniganesh'. When I print the value of s.substring(1, 2), the output is 'u' due to Java's indexing system. However, I now want to alter my string so that it starts with index po ...

What is the reason behind having to clear out the connection pool every time I deploy a new version?

After successfully establishing a connection to a remote MySQL server through Glassfish, I encountered an issue where any changes made to the code or XHTML files required me to manually flush the connection pool in the administrator panel of Glassfish. Oth ...

Choose a new file in the file selection window while the program is running

While working with Selenium web driver, I encountered a challenge when dealing with the File browse window. After trying various approaches, I eventually found a solution using AutoIt. Below is the script: @Test public void test() throws InterruptedE ...

Navigating through text after a specified label with XPath

Currently exploring Selenium for testing purposes, I've run into some issues. Let's say I have the following: <div class="itemize-row"> <p class="subText"> <span class="item-labe ...

"I'm looking for a way to efficiently pass variables between routes in Express when working with

Having some trouble passing variables from Express to node.js. Specifically, I'm trying to retrieve the IP address in the .js file. Here's my code snippet: app.get('/', function(req, res) { app.set('ipAddr' , req.ip); res ...

Retrieve JSON data using Google Chrome

I am encountering difficulties in fetching data from a local json file on my machine. Despite trying various solutions I found, I have been unsuccessful... Here is the code snippet I have used: When attempting to fetch the API, I encountered the error me ...

Performing a periodic sum on an array using Java 8 streams

I am looking to calculate a periodic sum on an array by summing values based on index modulo n. int size=100; double[] doubleArr = new double[size]; for (int i = 0; i < size; i++){ doubleArr[i]=Math.random(); } int n=2; double[] results= new double ...

Differences in React projects utilizing materialize-css compared to those using react-toolbox or material-ui

Is there a difference in technical benefits or code reliability when directly using material-css in JSX versus utilizing JSX specific libraries like material-ui or react-toolbox? Conversely, could using JSX libraries like material-ui or react-toolbox provi ...

Create a custom Iterateable interface that can hold only one element

I am working on a code snippet in which I need to return a single instance board to test the solution. Is there a better way to achieve this than placing it in a final List and then emptying it as the only option? public Iterable<Board> customSol ...

Exploring TypeScript Module Importation and WebPack Integration

Struggling with WebPack's injection of imported dependencies for a TypeScript project. The first challenge is getting TypeScript to recognize the imported module. In the header.ts file, there is a declaration of a module nested under vi.input, export ...

Struggling to organize data into a hierarchy using the D3.js nest function

Attempting to build a d3.js tree, I need my data to be in hierarchical form before using d3.treeLayout. Currently, here is what my json array looks like: var data = [ {"group":"1","price":"36599.88", "cy":"44260"}, {"group":"2","price":"36599 ...