JavaScript load a page on button click

前端 未结 4 1133
忘了有多久
忘了有多久 2020-12-13 08:27

I am trying to do a very simple task here, I would like to be able to click a button on a page and have it take me to another page. I have tried window.location.href, and a

4条回答
  •  感动是毒
    2020-12-13 08:58

    Just window.location = "http://wherever.you.wanna.go.com/", or, for local links, window.location = "my_relative_link.html".

    You can try it by typing it into your address bar as well, e.g. javascript: window.location = "http://www.google.com/".

    Also note that the protocol part of the URL (http://) is not optional for absolute links; omitting it will make javascript assume a relative link.

提交回复
热议问题