0

I'm trying to load multiple HTML pages into a JavaFx WebView from Java, but I only get the last added WebView added:

.java file

private void multiplePages() {
    webEngine.load("file:D:/head.html");
    webEngine.load("file:D:/body.html");
}

How can I go about adding multiple HTML pages into the same WebView

The HTML:

head.html

<div class="Head">
    <h3 class="panel-title">Page Head</h3>
</div>

body.html

<div class="Head">
    <h3 class="panel-title">Page Head</h3>
</div>

Thank you all in advance.

UPDATE:

The problem has been mentioned here: Cannot execute JavaScript when multiple WebViews are used at the same time, JDKJDK-8129398 as a bug.

This question is a follow-up to another I'd asked earlier: Error calling JavaScript from Java and netscape.javascript.JSException: SyntaxError: Unexpected keyword 'this'. Expected ')' to end a argument list. After digging around, I think this is the root of the problem, (that is, calling multiple HTMLs in the same WebView). I understand that it might not make much sense, but please note that the posted question is a very basic broken down piece of the actual problem I'm having. It's unavoidable that I have multiple HTMLs in the same WebView.

Community
  • 1
  • 1
Program-Me-Rev
  • 6,184
  • 18
  • 58
  • 142
  • This JDK-8129398 issue you that you link in your question appears unrelated to your question (your question code does not include any JavaScript which is what the JDK issue is relating to). – jewelsea Nov 09 '15 at 22:52
  • @jewelsea This question is a follow-up to another I'd asked earlier: [Error calling JavaScript from Java](http://stackoverflow.com/questions/33612267/error-calling-javascript-from-java). After digging around, I think this is the root of the problem, that is calling multiple HTMLs in the same WebView. I understand that it might not make much sense, but please note that the posted question is a very basic broken down piece of the actual problem I'm having. It's unavoidable that I have multiple HTMLs in the same WebView. – Program-Me-Rev Nov 09 '15 at 23:00

1 Answers1

1

A single WebView instance can only view a single HTML document at any given time.

Maybe you are would like to use an iframe, which would allow you to embed multiple HTML pages within a single HTML page? Though, in modern HTML development, use of iframes is often discouraged for many tasks as it has numerous drawbacks.

The standard way to achieve a header and body for a HTML page would be to use a templating language for HTML generation to compose multiple HTML fragments into a single HTML page. HTML templates are a subject that is too broad in scope of a StackOverflow answer. Composition of HTML templates can range in complexity from simple string appending to use of complicated processing technologies such as JSF. You may wish to research HTML templating separately.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406