Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Behavior of the URLLauncher service on different Browsers
Behavior of the URLLauncher service on different Browsers [message #1393729] Fri, 04 July 2014 07:20 Go to next message
Philipp Paland is currently offline Philipp PalandFriend
Messages: 2
Registered: July 2014
Junior Member
In our application, we're generating and storing different file types (Excel, PDF, ...) that we're making available for download via a line like this:

RWT.getClient().getService(UrlLauncher.class).openURL(url);

This works pretty well, especially on Firefox, which goes straight to a dialog asking the user to open or download the file. But in Chrome, a new browser window (not a tab!) is opened with the URL of the file, which is ok for Images or PDF files because they are the displayed in the browser window. For Excel files it shows the new window with the URL, the window content is empty and on the bottom Chrome display its download widget / button.

Is there any configuration for the URLLauncher I can provide so that the file opens in Chrome without the extra window?
Re: Behavior of the URLLauncher service on different Browsers [message #1396575 is a reply to message #1393729] Tue, 08 July 2014 14:00 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 389
Registered: July 2009
Senior Member
Hi.

> Is there any configuration for the URLLauncher I can provide so that the
> file opens in Chrome without the extra window?

Currently, no. The URLLauncher can not predict how the browser will deal
with the URL, so it opens a new window/tab (it doesn't know the
difference) to ensure the content is visible, but does not navigate away
from the RAP application. It would be feasible to let the application
developer decide how an URL should be treated (at their own risk), but
there is no API for that yet. You could open an enhancement request on
bugzilla if you want.

However, you can simply do what the URLLauchner can do directly using
the JavaScriptExecuter.

executer.execute( "window.location=\"" + url + "\";" );

I haven't tried it, but I think it should go directly go to the download
dialog, BUT ONLY IF THE BROWSER IS NOT CONFIGURED TO DISPLAY THE GIVEN
FILE DIRECTLY! In that case the RAP session would be terminated, so use
it at your own risk.

Greetings,
Tim

--
Tim Buschtöns

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Behavior of the URLLauncher service on different Browsers [message #1396657 is a reply to message #1396575] Tue, 08 July 2014 16:05 Go to previous message
Philipp Paland is currently offline Philipp PalandFriend
Messages: 2
Registered: July 2014
Junior Member
Thanks, this helps a lot!

I'm using a JavaScript snippet from Github -> PixelsCommander/Download-File-JS (The forum won't let me post the link) that's doing pretty much exactly what I want to do for Chrome / Safari / Opera and works in Firefox / IE, too:

                //RWT.getClient().getService(UrlLauncher.class).openURL(url);

                String js =
                        "window.downloadFile = function (sUrl) {" +
                            "if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || navigator.userAgent.toLowerCase().indexOf('safari') > -1) {" +
                                "var link = document.createElement('a');" +
                                "link.href = sUrl;" +
                                "if (link.download !== undefined) {" +
                                    "var fileName = sUrl.substring(sUrl.lastIndexOf('/') + 1, sUrl.length);" +
                                    "link.download = fileName;" +
                                "}" +
                                "if (document.createEvent) {" +
                                    "var e = document.createEvent('MouseEvents');" +
                                    "e.initEvent('click', true, true);" +
                                    "link.dispatchEvent(e);" +
                                    "return true;" +
                                "}" +
                            "}" +
                            "window.open(sUrl);" +
                            "return true;" +
                        "};" +
                        "window.downloadFile('" + url + "');";
                
                RWT.getClient().getService(JavaScriptExecutor.class).execute(js);

Previous Topic:TableViewer in IE9, problem with arrow-down keys
Next Topic:error occurred when adding markup to grid!
Goto Forum:
  


Current Time: Sat May 23 10:22:56 GMT 2015

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

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