Home > OS >  HTML button hyperlink not opening other files
HTML button hyperlink not opening other files

Time:11-07

I have a "html home page" and I want the button to direct to other local files in the browser. This works fine with hyperlinks but I got code for custom buttons that I want to use but they aren't allowing me to open local files just links. Code:

<html>
<body style="background-color:rgb(48, 45, 45)">
<font color="white">
<font color="#4CAF50">
<head>
<style>
b {
color: rgb(0, 0, 0);
background-color: rgb(252, 239, 0);
text-decoration: none;
padding: 10px 15px;
border-radius: 8px;
cursor: pointer;
}
</style>
</head>
<body>
</body>
</html>
<h1 style="text-align: center">Science</h1>
<b href="file:///D:\School Project\Physics.html">Physics</b>

Preview of the html code

CodePudding user response:

A solution is to make a link arround your button, you could use this code:

<a href="file:///D:\School Project\Physics.html"><b>Physics</b></a>

CodePudding user response:

Use the document.href.location For example:

<button onclick="goToHomePage">Click Me</button>
<script>
  function goToHomePage() {
    document.location.href = ''; // put the document location in between the quotation marks
  }
</script>

Or use <a> elements For example:

<a href="#">Click Me</a> <!-- put the document location in between the quotation marks instead of the '#'-->

  • Related