Found a work-around :
URL frameUrl;
try {
HttpURLConnection uCon = (HttpURLConnection)frameUrl.openConnection();
String frameSupport = uCon.getHeaderField("X-Frame-Options");
uCon.disconnect();
if(frameSupport==null)
iframe.setSrc(frameUrl.toString());
else{
log.log(Level.WARNING,"* FRAME NOT SUPPORTED, URL WILL BE OPENED IN NEW TAB *",e);
Executions.getCurrent().sendRedirect(frameUrl.toString(), "_blank");
}
} catch (WrongValueException e) {
log.log(Level.WARNING,"* WRONG URL VALUE *",e);
} catch (MalformedURLException e) {
log.log(Level.WARNING,"* INVALID URL FORMAT *",e);
} catch (IOException e) {
log.log(Level.WARNING,"* CAN NOT CONNECT TO URL *",e);
}
However, it's not an efficient solution in terms of performance since it sends request to URL destination to get a Http Response and check its Header to decide opening URL in iframe or new browser tab.
BTW, using Executions.getCurrent().sendRedirect(url,"_blank") , i ran into 2 problems:
- Browsers block popups and i had to configure browser setting to allow popup from my test site.
- Firefox seems to handle well when it opened url in new tab but Chrome was messed up opening url in a new popup window.
So it should be a better solution to find another method to open link in new tab instead of using Executions.getCurrent().sendRedirect(url,"_blank").