I have created a top bar with a sidemenu in order to navigate through multiple pages. I would like to display the page title in this top bar according to the page where it is loaded. This is my top bar:
function openNav() {
document.getElementById("mySidepanel").style.width = "280px";
}
function closeNav() {
document.getElementById("mySidepanel").style.width = "0";
}
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
body,html{
padding:0;margin:0;
background-color:#F4F4F4;
}
#wrapper-header{
color:white;
font-size: 28px;
float:left;
width:105%;
height:65px;
background-color:#2E2D30;
}
#main-header{
position:relative;
width:1200px;
left:50%;
margin-left:-580px;
height:auto;
}
.page-title{
position: absolute;
height: 20px;
left: 25%;
top: 45%;
transform: translate(-50%, -50%);
}
.sidepanel {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
font-family: 'Times New Roman', Times, serif;
overflow-x: hidden;
padding-top: 60px;
transition: 0.5s;
}
.sidepanel a, .dropdown-btn {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
border: none;
background: none;
transition: 0.3s;
outline: none;
font-family: 'Times New Roman', Times, serif;
}
.sidepanel a:hover, .dropdown-btn:hover {
color: #f1f1f1;
}
.sidepanel .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
.openbtn {
font-size: 20px;
cursor: pointer;
background-color: #2E2D30;
color: white;
padding: 10px 15px;
border: none;
transform: scale(1.6);
}
.openbtn:hover {
background-color: rgb(53, 53, 53);
}
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
font-family: 'Times New Roman', Times, serif;
}
.fa-caret-down {
margin-left: 18px;
float: right;
padding-right: 2px;
}
<div id="wrapper-header">
<div id="main-header" class="object">
<button class="openbtn" onclick="openNav()">☰</button>
<div class="page-title">PAGE TITLE</div>
</div>
</div>
<!-- NAVBAR -->
<div id="mySidepanel" class="sidepanel">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">Recientes</a>
<button class="dropdown-btn">Para empezar
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container">
<a href="#">Nivel 1-5</a>
<a href="#">Nivel 6-10</a>
<a href="#">Nivel 11-15</a>
</div>
<a href="#">Arreglos</a>
</div>
So basically it would be to display the page title in the element with the class "page-title". I am avoiding to use php so far because it is a static web page and I am hosting it locally. That is why I am including the html file in multiple pages using jquery instead of php or any other server side method.