I have a page where I have a flex table and a couple of rows.
I've added a onClcik event, and want that a variable which is available
to me is used as a link to open the url in the same window (not
Window.open("", "", "") as this opens a new window).
For example:
public void onCellClicked(SourcesTableEvents sender, int row, int cell)
{
// Select the row that was clicked (-1 to account for header row).
if (row > 0)
selectRow(row - 1);
}
private void selectRow(int row) {
// When a row (other than the first one, which is used as a header)
is
// selected, display its associated MailItem.
MailItem item = MailItems.getMailItem(startIndex + row);
if (item == null)
return;
Window.alert(item.url);
//External Link here
}
Basically, the URL does show in the alert. But how can I do something
like:
Window.location= item.url;
Where I keep the same window and do not open a new one?
Using Window.open just opens a new window...
A basic html page to explain what I mean about keeping it in the same
window:
<html>
<head></head>
<body>
<img src="http://www.google.com/images/logo_sm.gif"
onclick="window.location.href='http://www.google.com'">
</body>
</html>
Thank you for your time.
Much appreciated,
thank your for your input, I see the dilema.
However, I fully expect the window to visit another location and
completely leave my gwt site. That is the desired effect. I don't want
to have a table with text that you have to click like a simple <a
href>, but instead make the whole row into a link.
This can be achieved using:
<table width=100% border=1>
<tr>
<td>Hello</td>
</tr>
<tr onClick="window.location.href='http://www.google.com'">
<td>Goodbye</td>
</tr>
</table>
Is there an easy way to set the properties of a table row?
Even if there is, I'd still have to find a way to navigate the current
page away from it's current URL without opening a new window.
Perhaps I'm asking too much, and you shouldn't be able to do this, but
I don't really see why not =)
Thanks again for your help. I really appreciate it.
Best regards,
...
Image img = new Image("http://www.google.com/images/logo_sm.gif");
DOM.setStyleAttribute(img.getElement(), "cursor", "pointer");
img.addClickListener(new ClickListener()
{
public void onClick(Widget sender)
{
setLocation("http://www.google.com/");
}
});
RootPanel.get().add(img);
...
/**
* Sets the window.location.href to the specified url; thus
redirecting
* to said url.
*
* @param url The url to redirect to.
*/
public native void setLocation(String url) /*-{
$wnd.location.href = url;
}-*/;
...
Just one silly question though =) (theres always one):
What is $wnd? I certainly can't do Window.location.href, so in this
example, what does the $wnd reference?
Thanks for all the help.
Best regards,