リンクに target="_blank" があり、pdf を指している場合、Windows 7 で jxbrowser 4.9 を使用しています。
新しいポップアップが pdf プラグインに付属しています。
このpdfをダウンロードしたいので、そのポップアップでpdfプラグインを無効にしました。
PluginManager pluginManager = browser.getPluginManager();
pluginManager.setPluginFilter(new PluginFilter() {
@Override
public boolean isPluginAllowed(PluginInfo pluginInfo) {
return false;
}
});
ポップアップに「プラグインを読み込めませんでした」という黒い画面が表示されますが、pdf をダウンロードするようには勧められません。
リンクを変更して target="_blank" を抑制し、pdf プラグインを無効にすると、pdf をダウンロードできます。
target="_blank" のときに PDF をダウンロードするために特別なことはありますか?
ご協力いただきありがとうございます !
これが私の単純なクラスです: 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");
}
}
そして、これは test.html ページです:
<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>
任意の pdf を使用します。