本文整理汇总了Java中javafx.scene.web.WebEngine.setOnAlert方法的典型用法代码示例。如果您正苦于以下问题:Java WebEngine.setOnAlert方法的具体用法?Java WebEngine.setOnAlert怎么用?Java WebEngine.setOnAlert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.web.WebEngine
的用法示例。
在下文中一共展示了WebEngine.setOnAlert方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public void setup() {
this.dialog = new Dialog(this.root.getScene().getWindow());
this.pluginLoader = new PluginLoader(this.dialog, this.logger);
WebEngine webEngine = this.htmlRoot.getEngine();
webEngine.setOnAlert(event -> this.dialog.info(event.getData()));
webEngine.load(getClass().getResource("/page/index.html").toString());
this.htmlRoot.setFontSmoothingType(FontSmoothingType.GRAY);
this.htmlRoot.setContextMenuEnabled(false);
webEngine.getLoadWorker().stateProperty().addListener(
(ov, oldState, newState) -> {
if (newState == State.SUCCEEDED) this.onLoaded();
});
}
示例2: createWebView
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public static WebEngine createWebView(FXCanvas canvas) {
canvas.setLayout(new FillLayout());
WebView view = new WebView();
// When the WebEngine is initialized a CookieHandler is set, which has
// errors reading multi value cookies, therefore set to null again
CookieHandler.setDefault(null);
Scene scene = new Scene(view);
canvas.setScene(scene);
WebEngine webkit = view.getEngine();
webkit.setJavaScriptEnabled(true);
webkit.setOnAlert(e -> {
Logger log = LoggerFactory.getLogger(UI.class);
log.error("JavaScript alert: {}", e.getData());
});
return webkit;
}
示例3: urlChangeLis
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public final void urlChangeLis(final WebEngine engine, final TextField urlField, final Tab tab) {
engine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
if (newState == Worker.State.FAILED) {
File f = new File(new File(saveDir, engine.getLocation().replaceAll("[ : / . ]", "-").trim()),
engine.getLocation().replaceAll("[ : / . ]", "-").trim() + ".html");
if (f.exists()) {
try {
engine.load(f.toURI().toURL().toExternalForm());
} catch (MalformedURLException e) {
e.printStackTrace();
}
return;
}
engine.loadContent("Unable to load " + engine.getLocation().trim());
return;
}
});
engine.locationProperty().addListener((o,oU,nU) -> ZunoZapWebView.this.changed(engine, urlField, tab, oU, nU));
engine.setOnAlert((popupText) -> {
boolean bad = false;
if (popupText.toString().toLowerCase().contains("virus")) {
bad = true;
JOptionPane.showMessageDialog(null, "The site you are visting has tryed to create an popup with the word 'virus' in it, Please be carefull on this site", "ZunoZap AntiPopupVirus", JOptionPane.WARNING_MESSAGE);
}
if (allowPluginEvents()) for (PluginBase pl : p.plugins) pl.onPopup(bad);
JOptionPane.showMessageDialog(null, popupText.getData(), "JS Popup", JOptionPane.INFORMATION_MESSAGE);
});
engine.titleProperty().addListener((ov, o, n) -> tab.setText(n));
}
示例4: setWebEngineHandlers
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
/**
* ウェブエンジンの各種ハンドラを設定する.
*
* @param engine
* 対象のウェブエンジン
*/
private void setWebEngineHandlers(WebEngine engine) {
// JavaScriptのalert, confirm, prompt関数に対応するハンドラ
engine.setPromptHandler(createPromptHandler());
engine.setConfirmHandler(createConfirmHandler());
engine.setOnAlert(createAlertHandler());
// 別ブラウザウィンドウを開くハンドラ
engine.setCreatePopupHandler(createPopupHandler(engine));
}
示例5: connectBackendObject
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
/**
* Registers a backend Java object as a Javascript variable.
* The real connection to the webEngine comes when the javascript performs
* an special "alert" message by invoking
* "alert('__CONNECT__BACKEND__varname')" where varname is the javascript
* variable we want to make available.
*
* The call to this function has to be performed before the engine loads the
* first page (where the alert call should take place).
*
* @param webEngine The webEngine to register the new variable.
* @param varname The name of the variable in javascript.
* @param backend The Java backend object.
*/
public static void connectBackendObject(
final WebEngine webEngine,
final String varname,
final Object backend) {
registerBackendObject(webEngine, varname, backend);
// create a onAlertChangeListener. We always want to listen
// to onAlert events, since via this event, the javascript front-end
// will send us an special "alert" message asking to connect the
// backend object as soon as possible(*).
// However, if the programmer also wants to set
// his own onAlert handler for this web engine,
// we will create a handlerwrapper with our
// behavior plus the programmer's one.
// (*) It was impossible for me to re-connect the backend object
// when the users navigates from one page to another page where the
// backend object was also needed. The navigation erases any javascript
// variables, so the backend has to be reconnected. However,
// The recommended state change listeners on
// webEngine were executed too late, after javascript code asking for the
// backend object is executed, so it was not a solution.
// The only way I found is to place a custom javacript "signaling"
// code to ask Java to reconnect the backend object.
// The solution was "alert", because we can listen to alert calls from
// javascript, so via an special "alert" message, we can connect the
// backend object again.
// It is not a bad solution, because the programmer has only to inlude
// a simple additional script (such as "mybackend.js") in the page
// before any other scripts uses the backend variable.
if (!webEnginesWithAlertChangeListener.contains(webEngine)) {
if (webEngine.getOnAlert() == null) {
webEngine.setOnAlert(new AlertEventHandlerWrapper(webEngine,
null));
}
webEngine.onAlertProperty().addListener(
new ChangeListener<EventHandler<WebEvent<String>>>() {
@Override
public void changed(
ObservableValue
<? extends EventHandler<WebEvent<String>>> arg0,
EventHandler<WebEvent<String>> previous,
final EventHandler<WebEvent<String>> newHandler) {
if (!changing) { // avoid recursive calls
changing = true;
webEngine.setOnAlert(
new AlertEventHandlerWrapper(
webEngine,
newHandler));
changing = false;
}
}
});
}
webEnginesWithAlertChangeListener.add(webEngine);
}
示例6: initEngine
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
private void initEngine(){
engine = new WebEngine();
engine.setOnAlert(this);
correctHandlerReturned = (this == engine.getOnAlert());
}
示例7: SearchViewPane
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
public SearchViewPane() {
ExileToolsLadderService exileToolsLadderService = new ExileToolsLadderService();
exileToolsLadderService.restart();
// FIXME, hacky
if (!Main.DEVELOPMENT_MODE) {
while (exileToolsLadderService.resultProperty().getValue().equals("{}")) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
// FIXME, hacky
SearchViewRendererCallback blueMarlineCallback = new SearchViewRendererCallback();
if (Main.RAW_RENDERER_ENABLED) {
RawSearchViewRenderer viewRenderer = new RawSearchViewRenderer();
viewRenderer.searchProperty().bind(search);
getChildren().add((Node)viewRenderer);
} else {
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
search.addListener((observ, oldVal, newValue) -> {
if (newValue != null) {
String renderer = search.getValue().getSearchFile().getRenderer();
if (renderer.startsWith("renderers")) {
renderer = Paths.get(renderer).toAbsolutePath().toUri().toString();
}
webEngine.load(renderer);
}
});
webEngine.getLoadWorker().stateProperty().addListener((observ, oldVal, newVal) -> {
if (newVal.equals(Worker.State.SUCCEEDED)) {
JSObject window = (JSObject) webEngine.executeScript("window");
window.setMember("blueMarlineCallback", blueMarlineCallback);
window.setMember("searchFile", search.getValue().getSearchFile());
window.setMember("searchResult", search.getValue().getSearchResult());
window.setMember("ladderOnlinePlayers", exileToolsLadderService.resultProperty().getValue());
webEngine.executeScript("onBluemarlineReady()");
}
});
// setup callbacks
webEngine.setOnAlert(e -> Dialogs.showInfo(e.getData()));
getChildren().add(webView);
}
}
示例8: connectBackendObject
import javafx.scene.web.WebEngine; //导入方法依赖的package包/类
/**
* Registers a backend Java object as a Javascript variable.
* The real connection to the webEngine comes when the javascript performs
* an special "alert" message by invoking
* "alert('__CONNECT__BACKEND__varname')" where varname is the javascript
* variable we want to make available.
*
* The call to this function has to be performed before the engine loads the
* first page (where the alert call should take place).
*
* @param webEngine The webEngine to register the new variable.
* @param varname The name of the variable in javascript.
* @param backend The Java backend object.
*/
public static void connectBackendObject(
final WebEngine webEngine,
final String varname,
final Object backend) {
registerBackendObject(webEngine, varname, backend);
// create a onAlertChangeListener. We always want to listen
// to onAlert events, since via this event, the javascript front-end
// will send us an special "alert" message asking to connect the
// backend object as soon as possible(*).
// However, if the programmer also wants to set
// his own onAlert handler for this web engine,
// we will create a handlerwrapper with our
// behavior plus the programmer's one.
// (*) It was impossible for me to re-connect the backend object
// when the users navigates from one page to another page where the
// backend object was also needed. The navigation erases any javascript
// variables, so the backend has to be reconnected. However,
// The recommended state change listeners on
// webEngine were executed too late, after javascript code asking for the
// backend object is executed, so it was not a solution.
// The only way I found is to place a custom javacript "signaling"
// code to ask Java to reconnect the backend object.
// The solution was "alert", because we can listen to alert calls from
// javascript, so via an special "alert" message, we can connect the
// backend object again.
// It is not a bad solution, because the programmer has only to inlude
// a simple additional script (such as "mybackend.js") in the page
// before any other scripts uses the backend variable.
if (!webEnginesWithAlertChangeListener.contains(webEngine)) {
if (webEngine.getOnAlert() == null) {
webEngine.setOnAlert(new AlertEventHandlerWrapper(webEngine,
null));
}
webEngine.onAlertProperty().addListener(
new ChangeListener<EventHandler<WebEvent<String>>>() {
@Override
public void changed(
ObservableValue
<? extends EventHandler<WebEvent<String>>> arg0,
EventHandler<WebEvent<String>> previous,
final EventHandler<WebEvent<String>> newHandler) {
if (!changing) { // avoid recursive calls
changing = true;
webEngine.setOnAlert(
new AlertEventHandlerWrapper(
webEngine,
newHandler));
changing = false;
}
}
});
}
webEnginesWithAlertChangeListener.add(webEngine);
}