JavaFX - WebView:阻止弹出窗口或在新窗口中打开

时间:2021-10-27 17:04:54

I've a website, here I display an <iframe> with video player.

我有一个网站,在这里我用视频播放器显示

Thats videos are uploaded to Powvideo. Powvideo put some popups with ads in the player.

那些视频上传到Powvideo。 Powvideo在播放器中添加了一些广告。

Now I'm developing a desktop aplication. I use JavaFX to load the url of my site.

现在我正在开发一个桌面应用程序。我使用JavaFX加载我的网站的网址。

The problem is, when try to see some video, this popups open in same page, so the user can't view anything. The page redirect to the ads windows.

问题是,当试图看到一些视频时,这个弹出窗口会在同一页面中打开,因此用户无法查看任何内容。该页面重定向到广告窗口。

My code:

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.scene.image.Image;

public class Main extends Application {

  VBox vb = new VBox();

  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage stage) {

    vb.setId("root");

    WebView  browser = new WebView();
    WebEngine engine = browser.getEngine();

    String url = "http://xxx.xxxxx.net/";
    engine.load(url);

    vb.setAlignment(Pos.CENTER);
    vb.getChildren().addAll(browser);

    Scene scene = new Scene(vb, 1024, 600);

    stage.setTitle("Series EnLatino");
    stage.setScene(scene);
    stage.show(); 

    stage.getIcons().add(new Image("iconoAplicacionWindows.png"));

    }
}

This are a test of the player, with these uglies ads http://powvideo.net/embed-d45fwobyzyup.html

这是玩家的测试,这些uglies广告http://powvideo.net/embed-d45fwobyzyup.html

When you play the video or click anywhere of player, the popads open. In Webaplication, this popads open in same windows.

当您播放视频或点击播放器的任何位置时,弹出窗口将打开。在Webaplication中,这个popad在相同的窗口中打开。

How can prevent this? Or how can make that popups open under the webapp?. It's this possible?

怎么能阻止这个?或者如何在webapp下打开弹出窗口?这可能吗?

Thanks.

1 个解决方案

#1


You can try providing your own WebEngine "popup" or "alert" handlers, and then silently ignoring those requests..

您可以尝试提供自己的WebEngine“弹出”或“警报”处理程序,然后默默地忽略这些请求。

https://docs.oracle.com/javafx/2/api/javafx/scene/web/WebEngine.html#setOnAlert(javafx.event.EventHandler)

#1


You can try providing your own WebEngine "popup" or "alert" handlers, and then silently ignoring those requests..

您可以尝试提供自己的WebEngine“弹出”或“警报”处理程序,然后默默地忽略这些请求。

https://docs.oracle.com/javafx/2/api/javafx/scene/web/WebEngine.html#setOnAlert(javafx.event.EventHandler)