如何将多个html页面添加到同一个WebView [英] How to add multiple html pages to the same WebView

查看:956
本文介绍了如何将多个html页面添加到同一个WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Java中将多个HTML页面加载到JavaFx WebView中,但我只添加了最后添加的WebView:

.java文件

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

如何添加多个HTML页面到同一个WebView中



HTML:

head.html

 < div class =Head> 
< h3 class =panel-title>页首< / h3>
< / div>

body.html

 < div class =Head> 
< h3 class =panel-title>页首< / h3>
< / div>

谢谢大家。

更新:



问题已被提及这里:当多个WebView被同时使用时,不能执行JavaScript,JDKJDK-8129398 作为bug。

这个问题是我之前询问的另一个后续问题:从Java调用JavaScript时出错 netscape.javascript.JSException:SyntaxError:意外关键字'this' 。预期')'结束参数列表。经过深入研究,我认为这是问题的根源,(即,在同一个WebView中调用多个HTML)。我明白这可能没有多大意义,但请注意,发布的问题是我遇到的实际问题的一个非常基本的细分部分。在同一WebView中有多个HTML是不可避免的。

解决方案

单个WebView实例只能查看任何一个HTML文档给定的时间。

也许你想使用 iframe ,这将允许您在一个HTML页面中嵌入多个HTML页面?尽管在现代HTML开发中,iframe的使用通常是因许多任务而不鼓励有许多缺点。

实现HTML页面的标题和正文的标准方法是使用HTML生成的模板语言将多个HTML片段合并到单个 HTML页面。 HTML模板是StackOverflow答案的范围过于宽泛的主题。 HTML模板的组成可以从简单的字符串追加到复杂的处理技术(如JSF)的复杂性。您可能希望单独研究HTML模板。


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.

解决方案

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.

这篇关于如何将多个html页面添加到同一个WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆