How to make a button link to another html page?
button.addClickHandler(new ClickHan开发者_如何学Pythondler() {
public void onClick(ClickEvent event) {
//this code has to redirect to another page within the project
}
The question is tagged as GWT so based on that... to do it entirely on the client, you can use the com.google.gwt.user.client.Window
class.
Window.open(linkURL, "_self", "");
Here's a link to the docs.
Look under gwt javadocs for the Window class. There are some static members in the Window class.
The open function is the same as that in javascript:
Window.open(url, targetFrame, features )
In GWT, "_self" is the name of the current active display frame/window.
Location replace, just as in javascript:
Window.location.replace(url)
Display alert or confirm window:
Window.alert(msg)
Window.confirm(msg)
If you wanted a button but not in the script you can try this:
<a href="//Wherever your page is//">YOUR PAGE</a>
<a href="https://stackoverflow.com/">Stack Overflow</a>
No need to use JS. As of HTML5, buttons support the formaction
attribute where you can specify the URL.
<form>
<button formaction="http://stackoverflow.com">Go to stackoverflow!</button>
</form>
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction
精彩评论