问题
I'm using primefaces tagcloud. But when i clicked on the links given on the tagcloud, it opened in that same window.But on clicking the tagcloud links it should open in a new window not on the same window. I want a new window will open when i click on the tagcloud links. Can anyone please help me about this topics ???
回答1:
JavaScript solution:
One possible approach could be JavaScript:
<p:tagCloud model="#{tagCloudBean.model}" onclick="preventDefault(event)">
<p:ajax event="select" update="msg" listener="#{tagCloudBean.onSelect}" />
</p:tagCloud>
onclick triggers a JavaScript function which prevents the link from getting opened.
function preventDefault(e) {
e.preventDefault();
}
Also, by adding an ajax event you can call a listener in your managed bean.
public void onSelect(SelectEvent event) {
TagCloudItem item = (TagCloudItem) event.getObject();
String url = item.getUrl();
String script = "window.open('" + url + "');"
RequestContext.getCurrentInstance().execute(script);
}
There you can access the url of the TagCloudItem and execute a JavaScript statement which should open a new browser window.
This possible solution is untested, but just give it a try.
来源:https://stackoverflow.com/questions/24133140/open-primefaces-tagcloud-links-in-a-new-window