Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335168 - Support open of links in new browser tabs or windows
Summary: Support open of links in new browser tabs or windows
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 1.5 M6   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-24 05:55 EST by Gunnar Wagenknecht CLA
Modified: 2012-03-29 09:04 EDT (History)
3 users (show)

See Also:


Attachments
Browser widget vs. FormText (16.69 KB, image/png)
2011-02-08 03:21 EST, Gunnar Wagenknecht CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gunnar Wagenknecht CLA 2011-01-24 05:55:17 EST
ExternalBrowser#open currently *ALWAYS* opens as a pop up windows. This has several drawebacks. Most notably the operation is blocked by a pop-up blocker (tested in FF, Chrome).

This is somehow related to Bug #267831. In order to allow opening in new browser tabs or windows the the window name "_blank" (or none at all) must be used when calling JavaScript.

For details see here:
 http://www.webreference.com/js/tutorial1/open.html
Comment 1 Ivan Furnadjiev CLA 2011-02-03 08:25:32 EST
I did some testing today about this issue. Here are the results in all browsers - FF, IE, Safari, Chrome, Opera:
1. Window name is not important - "_blank" or not, a new window/tab is opened.
2. Popup blocker ALWAYS (if not disabled by the user) blocks the new opened tab/window - created by window.open.
3. Opening a new window or tab is controlled by browser user preferences.
For me the conclusion is that, everything opened by window.open (javascript) is treated as popup and potentially blocked by browser Popup Blocker.
Opening a window/tab by user interaction (click on a link for example) is a different story.
Comment 2 Rüdiger Herrmann CLA 2011-02-03 08:48:49 EST
I would like to add to comment #1 that the window name in window.open() controls whether a new window or tab is opened or not. If there is already a window/tab with the same name then this window is reused. The given URL is loaded in this window, replacing the former content. If there is no window open with the name then a new window is opened. To my knowledge, the window name "_blank" has the special meaning to always open a *new* window/tab.
Comment 3 Gunnar Wagenknecht CLA 2011-02-03 09:44:09 EST
I wonder if there is a reliable way for RAP applications to open new tabs/windows from a push button what doesn't get blocked by popup blockers?

Looks like the only option is a hyperlink widget?
Comment 4 Ivan Furnadjiev CLA 2011-02-03 10:12:57 EST
Maybe another easy option is a Browser widget with HTML page that renders a simple HTML button. Here are some examples http://www.pageresource.com/jscript/jwinopen.htm
Comment 5 Rüdiger Herrmann CLA 2011-02-03 11:46:50 EST
(In reply to comment #3)
> I wonder if there is a reliable way for RAP applications to open new
> tabs/windows from a push button what doesn't get blocked by popup blockers?
> 
> Looks like the only option is a hyperlink widget?

Right now you can use the Browser widget to emulate what you want. Take a Browser widget and call its setText() method with a string like this:
  <a href="url-new-document" target="window-name/_blank/...">Click Me</a>
What you get is a link to the new document within your application. 
Alternatively you may replace the <a> tag with an <input type=button> and provide some Javascript to react when it is selected.
Comment 6 Gunnar Wagenknecht CLA 2011-02-08 03:21:33 EST
Created attachment 188499 [details]
Browser widget vs. FormText

I tried using the Browser widget. Unfortunately, it doesn't fly because of the different default formatting.

Can't the FormText be "enhanced" to implicitly support http:// https:// links?
Comment 7 Ivan Furnadjiev CLA 2011-02-08 04:23:00 EST
Gunnar, I don't understand your request. Could you provide a small FormText snippet to show where you need these schemes?
Comment 8 Gunnar Wagenknecht CLA 2011-02-08 05:15:15 EST
Here is an example:

final FormText welcomeText = toolkit.createFormText(client, false);
welcomeText.setText("<text><p>Some text with a link to our <a href=\"http://www.eclipse.org/gyrex/\" alt=\"Open the Gyrex blog.\">blog</a>.</p></text>", true, true);
		

As you can see, the text contains a vanilla HTML link. In order to trigger it I need to register a hyperlink listener.


welcomeText.addHyperlinkListener(new HyperlinkAdapter() {
 @Override
 public void linkActivated(final HyperlinkEvent e) {
  final Object href = e.getHref();
  if ((href instanceof String) && (StringUtils.startsWith((String) href, "http://") || StringUtils.startsWith((String) href, "https://"))) {
   ExternalBrowser.open("_blank", (String) href, 0);
  }
 }
});


Unfortunately, that always triggers the pop-up blocker.
Comment 9 Rüdiger Herrmann CLA 2011-02-08 06:42:54 EST
(In reply to comment #6)
> Created attachment 188499 [details]
> Browser widget vs. FormText
> 
> I tried using the Browser widget. Unfortunately, it doesn't fly because of the
> different default formatting.
Couldn't the formatting be fixed with some inline CSS?
Comment 10 Gunnar Wagenknecht CLA 2011-02-08 06:57:39 EST
(In reply to comment #9)
> Couldn't the formatting be fixed with some inline CSS?

It should be the same CSS that is used by FormText. Do you have a hint where this is used? Maybe it's easy accessible.
Comment 11 Rüdiger Herrmann CLA 2011-02-08 07:36:43 EST
(In reply to comment #10)
> (In reply to comment #9)
> > Couldn't the formatting be fixed with some inline CSS?
> 
> It should be the same CSS that is used by FormText. Do you have a hint where
> this is used? Maybe it's easy accessible.

This is the default CSS for the FormText widget:
FormText {  
  color: black;
  background-color: rgb( 255, 255, 255 );
  font: 11px 'Segoe UI', Corbel, Calibri, Tahoma, 'Lucida Sans Unicode', sans-serif;  
  border: none;
}

The snippet was taken from FromText.default.css in package org.eclipse.ui.forms.internal.widgets.formtextkit in plug-in org.eclipse.rap.ui.forms
Comment 12 Ivan Furnadjiev CLA 2012-03-29 07:28:57 EDT
With the bug 355861 fixed, we can now add a markup to the Label including HTML hyperlinks. The hyperlink styling can be controlled by the Label styling (font, background color...) or inline style attribute of the <a> tag. Gunnar, does it fit your needs? Can we close it as obsolete?
Comment 13 Gunnar Wagenknecht CLA 2012-03-29 07:43:41 EDT
(In reply to comment #12)
> Gunnar, does it fit your needs? Can we close it as obsolete?

Yes. I saw it working on Ralf's machine yesterday!
Comment 14 Ivan Furnadjiev CLA 2012-03-29 09:04:12 EDT
(In reply to comment #13)
> Yes. I saw it working on Ralf's machine yesterday!
Fixed by adding markup support for Label (bug bug 355861).