在新窗口中打开 primefaces tagcloud 链接 [英] Open primefaces tagcloud links in a new window
问题描述
我使用的是primefaces tagcloud.但是当我点击 tagcloud 上给出的链接时,它在同一个窗口中打开.但是点击 tagcloud 链接时,它应该在一个新窗口中打开,而不是在同一个窗口中.我希望当我点击 tagcloud 链接时会打开一个新窗口.任何人都可以帮我解决这个话题吗???
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 ???
推荐答案
JavaScript 解决方案:
一种可能的方法是 JavaScript:
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 触发一个 JavaScript 函数,防止链接被打开.
onclick triggers a JavaScript function which prevents the link from getting opened.
function preventDefault(e) {
e.preventDefault();
}
此外,通过添加 ajax 事件,您可以在托管 bean 中调用侦听器.
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);
}
在那里您可以访问 TagCloudItem 的 url 并执行一个 JavaScript 语句,该语句应该打开一个新的浏览器窗口.
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.
这篇关于在新窗口中打开 primefaces tagcloud 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!