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

后端 未结 30 3591
长发绾君心
长发绾君心 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 05:02

    Why not just place your button inside of a reference tag e.g

    
    

    This seems to work perfectly for me and does not add any %20 tags to the link, just how you want it. I have used a link to google to demonstrate.

    You could of course wrap this in a form tag but it is not necessary.

    When linking another local file just put it in the same folder and add the file name as the reference. Or specify the location of the file if in is not in the same folder.

    
    

    This does not add any character onto the end of the URL either, however it does have the files project path as the url before ending with the name of the file. e.g

    If my project structure was...

    .. denotes a folder - denotes a file while four | denote a sub directory or file in parent folder

    ..public
    |||| ..html
    |||| |||| -main.html
    |||| |||| -secondary.html

    If I open main.html the URL would be,

    http://localhost:0000/public/html/main.html?_ijt=i7ms4v9oa7blahblahblah
    

    However, when I clicked the button inside main.html to change to secondary.html, the URL would be,

    http://localhost:0000/public/html/secondary.html 
    

    No special characters included at the end of the URL. I hope this helps. By the way - (%20 denotes a space in a URL its encoded and inserted in the place of them.)

    Note: The localhost:0000 will obviously not be 0000 you'll have your own port number there.

    Furthermore the ?_ijt=xxxxxxxxxxxxxx at the end off the main.html URL, x is determined by your own connection so obviously will not be equal to mine.


    It might seem like I'm stating some really basic points but I just want to explain as best as I can. Thank you for reading and I hope this help someone at the very least. Happy programming.

提交回复
热议问题