开发者

Make browser go to different url on button click?

开发者 https://www.devze.com 2023-01-15 11:49 出处:网络
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>开发者_开发百科;

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


$('#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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消