Open new Tab when button is clicked

有些话、适合烂在心里 提交于 2020-01-03 03:13:11

问题


using wicket I want to open a new tab when a button or link is clicked, how can I achieve it?

what I have managed to do is to open it in a pop up like this:

 PopupSettings popupSettings = new  PopupSettings("popuppagemap").setLeft(0).setHeight(500).setWidth(500).setHeight(0);

    // Popup example
final Link<Void> setPopupSettings = new BookmarkablePageLink<Void>("searchBtn", HomePage.class)
   .setPopupSettings(popupSettings);

but this opens it in a new window.


回答1:


no problem to open a link in a new tab: just add 'target="_blank"' to the link.

final Link<Void> link = new BookmarkablePageLink<Void>("link", HomePage.class){
    @Override
    protected void onComponentTag(ComponentTag tag) {
        super.onComponentTag(tag);
        tag.put("target", "_blank");
    }
};
add(link);



回答2:


This is not a function of Wicket but of your browser and HTML in general.

simply add a target tag to your link:

<a href="#" target="_blank" wicket:id="myCoolLink">My Cool Link</a>

What actually happens when the link is clicked will depend on the browser. Before browsers had tabs, this would have opened a new window, now most browsers will open a new tab by default, however, you can't depend on that happening because the feature is optional.




回答3:


If you want a button instead of a link that opens a new tab you can use:

html:

<a wicket:id="tabFormViewEmpBut"><button type="button">Click Me!</button></a>

And

Java wicket:

final Link<Void> link = new BookmarkablePageLink<Void>("tabFormViewEmpBut", HomePage.class) {
   @Override
   protected void onComponentTag(ComponentTag tag) {
     super.onComponentTag(tag);
     tag.put("target", "_blank");
   }
};
add(link);


来源:https://stackoverflow.com/questions/18121236/open-new-tab-when-button-is-clicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!