Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Open new window/popup and show custom html with css
Open new window/popup and show custom html with css [message #1837142] Fri, 22 January 2021 16:17 Go to next message
Chris Merg is currently offline Chris MergFriend
Messages: 12
Registered: January 2018
Junior Member
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 16:20]

Report message to a moderator

Re: Open new window/popup and show custom html with css [message #1837222 is a reply to message #1837142] Mon, 25 January 2021 12:23 Go to previous messageGo to next message
Sebastian Habenicht is currently offline Sebastian HabenichtFriend
Messages: 42
Registered: January 2013
Member
You could use a jface Dialog or PopupDialog which contains an org.eclipse.swt.browser.Browser to show the html + css. Add a button or action to the dialog which calls Browser#evaluate with "window.print();" as script to execute on that browser instance.
It worked for me that way (to only print the iframe's content).

[Updated on: Tue, 26 January 2021 15:35]

Report message to a moderator

Re: Open new window/popup and show custom html with css [message #1838407 is a reply to message #1837142] Wed, 24 February 2021 11:56 Go to previous message
Benjamin Wolff is currently offline Benjamin WolffFriend
Messages: 136
Registered: July 2009
Senior Member
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 11:57]

Report message to a moderator

Previous Topic:Custom RichTextEditor Fontsizes
Next Topic:Eclipse RAP application in horizontally scaled Azure WebApp Container
Goto Forum:
  


Current Time: Fri Mar 29 11:57:42 GMT 2024

Powered by FUDForum. Page generated in 0.03865 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top