How to create an HTML button that acts like a link?

后端 未结 30 3697
长发绾君心
长发绾君心 2020-11-21 04:18

I would like to create an HTML button that acts like a link. So, when you click the button, it redirects to a page. I would like it to be as accessible as possible.

30条回答
  •  暖寄归人
    2020-11-21 04:57

    Type window.location and press enter in your browser console. Then you can get the clear idea what location contains

       hash: ""
       host: "stackoverflow.com"
       hostname: "stackoverflow.com"
       href: "https://stackoverflow.com/questions/2906582/how-to-create-an-html-button- 
       that-acts-like-a-link"
       origin: "https://stackoverflow.com"
       pathname: "/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link"
       port: ""
       protocol: "https:"
    

    You can set any value from here.

    So For redirect another page you can set href value with your link.

       window.location.href = your link
    

    In Your Case-

       
    

提交回复
热议问题