简体   繁体   中英

How do I make my HtmlMenuItem open a URL in a new tab?

I am using richFaces 3.3.3.

I need to make a menuItem open a new tab with a simple URL ... for example google.com. For now I tried this code:

HtmlMenuItem menuItem = new HtmlMenuItem();
menuItem.setid("id");
menuItem.setValue("My menu link new tab");

menuItem.setSubmitMode("server");
menuItem.setTarget("_blank");
menuItem.setOnClick("document.location.href='www.gooogle.com'");

But this makes my current tab is redirected to google, and open a new tab with the context in which I was. I want to stay in my place, and the new tab "_blank" go to google.

I tried to replace onClick by onComplete, but this make new tab enter in my context too. But don't execute I tried to put an HtmlOutputLink as children of my menuItem, but not execute a click for outPutLink .. execute a click for menuItem ...

HtmlMenuItem menuItem = new HtmlMenuItem();
menuItem.setid("id");
menuItem.setValue("My menu link new tab");
HtmlOutputLink cLink = new HtmlOutputLink();
cLink.setTarget("_blank");
cLink.setValue("www.google.com");
menuItem.getChildren().add(cLink);

You can use only a OutputLink, something like:

HtmlOutputLink cLink = new HtmlOutputLink();
cLink.setValue("http://www.google.com");
cLink.setTarget("_blank");
HtmlOutputLabel label = new HtmlOutputLabel();
label.setValue("Google");
cLink.getChildren().add(label);

So, just add your link on some component. Maybe HtmlMenuItem use javascript to open the page and your browser see it like a Pop-up.

Are you using this? <ui:include src="#{bean.link}"/>

Your question is not really precise, so I just could come up with this idea ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM