1

i'm using jxbrowser 4.9 on windows 7, when a link has a target="_blank" and point to a pdf,

a new popup is coming with the pdf plugin,

as i want to download this pdf, i disabled the pdf plugin in that popup, via

PluginManager pluginManager = browser.getPluginManager();
pluginManager.setPluginFilter(new PluginFilter() {
  @Override
  public boolean isPluginAllowed(PluginInfo pluginInfo) {
    return false;
  }
});

the popup shows a black screen with "couldn't load plugin" but not offers me to download the pdf.

If i change the link to suppress the target="_blank", and disabled the pdf plugin, the pdf can be downloaded.

Is there a special thing to do to get a pdf downloaded when target="_blank"?

thanks for your help !

Here is my simple class : public class TestPopupPDF {

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            initAndDisplayUI();
        }
    });
}

private static void initAndDisplayUI() {
    Browser browser = BrowserFactory.create();

    JFrame frame = new JFrame("JxBrowser - Popup PDF test");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.add(browser.getView().getComponent(), BorderLayout.CENTER);
    frame.setSize(500, 400);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    PluginManager pluginManager = browser.getPluginManager();

    pluginManager.setPluginFilter(new PluginFilter() {
        @Override
        public boolean isPluginAllowed(PluginInfo pluginInfo) {
            //disable all plugins
            return false;
        }
    });

    browser.setPopupHandler(new PopupHandler() {
        public PopupContainer handlePopup(PopupParams params) {
            return new PopupContainer() {
                public void insertBrowser(final Browser browser,
                        Rectangle initialBounds) {
                    initialBounds.setBounds(100, 100, 500, 400);

                    JComponent component = browser.getView().getComponent();
                    component.setPreferredSize(initialBounds.getSize());

                    final JFrame frame = new JFrame("Popup");
                    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                    frame.add(component, BorderLayout.CENTER);
                    frame.pack();

                    frame.setLocation(initialBounds.getLocation());
                    frame.setVisible(true);
                    frame.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                            browser.dispose();
                        }
                    });

                    PluginManager pluginManager = browser.getPluginManager();

                    pluginManager.setPluginFilter(new PluginFilter() {
                        @Override
                        public boolean isPluginAllowed(PluginInfo pluginInfo) {
                            return false;
                        }
                    });
                }
            };
        }
    });


    browser.loadURL("http://localhost/test.html");

}

}

And this is the test.html page :

<html>
<head></head>
<body>
<H1>PDF</H1>
<a href="javascript.pdf" target="_blank">download/open pdf file new page</a>
<br><br>
<a href="javascript.pdf">download/open pdf file same page</a>

</body>
</html>

use any pdf.

4

1 回答 1

0

不再支持 JxBrowser 4.9。在JxBrowser 6.1中,此问题无法重现,因此我建议您尝试 6.1。

于 2016-02-09T11:55:59.377 回答