Ferrmolina
Ferrmolina

Reputation: 2771

JavaFX - WebView: Prevent Popups or open in new window

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.

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

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

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

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

Thanks.

Upvotes: 1

Views: 1169

Answers (1)

Buddy
Buddy

Reputation: 11038

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

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

Upvotes: 1

Related Questions