user246114
user246114

Reputation: 51721

Make browser go to different url on button click?

I've got a jquery-ui button. When clicked, I want to move the browser to a url within my domain:

<button onclick='foo'>Go</button>

function foo() {
    window.location('/otherpage');
}

is that the right way to do it, and address it relatively? Is there a better way to do this?

Thanks

Upvotes: 0

Views: 7576

Answers (2)

Aidan Brumsickle
Aidan Brumsickle

Reputation: 657

It should be window.location = '/otherpage'; Other than that I think it's fine.

Upvotes: 1

supakeen
supakeen

Reputation: 2924

$('#button-id').click(function() { window.location.pathname = '/otherpage'; });

What do you mean by relatively? To the current page or to the current host? There are a few options you are able to use.

Upvotes: 2

Related Questions