Open new window/popup and show custom html with css [message #1837142] |
Fri, 22 January 2021 11:17  |
Eclipse User |
|
|
|
Hi guys,
Is it possible to open a new popup/window and show custom html + css? We need to enable printing custom html/css.
So let's say I've got some html + css code and when the user clicks on a button a new window/popup opens displaying the page using this html + css. With that the user is able to use the print function (CTRL + P) to print the popup's view.
Thanks in Advance,
Chris
[Updated on: Fri, 22 January 2021 11:20] by Moderator
|
|
|
|
Re: Open new window/popup and show custom html with css [message #1838407 is a reply to message #1837142] |
Wed, 24 February 2021 06:56  |
Eclipse User |
|
|
|
Hi Chris,
I basically do it in the same way as Sebastian suggested. I open a new popup Dialog (based on the org.eclipse.jface.dialogs.Dialog class), add a org.eclipse.swt.browser.Browser widget, apply a layout on it so it fills the whole space of the dialog (and increases size automatically with it) and then add the HTML payload to it using the Browser#setText method.
String htmlWithCss = createHtmlContent()
Browser browser = new Browser(parent, SWT.NONE);
browser.setText(htmlWithCss);
GridDataBuilder.on(browser).withFill();
The Browser widget renders the HTML it gets via #setText in an iframe, so it can contain whatever HTML, CSS and JS and even refer to static resources by URL. So I basically generate a <html></html> page to display my stuff. You could then inline the CSS in the header section and add the HTML in the body section. Works pretty well.
HTH,
Ben
[Updated on: Wed, 24 February 2021 06:57] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03973 seconds