javascript sidebar stay open on page change
<p>im a bit of a newbie on JS stuff , mostly use bootstrap ready solutions , but now i want to implement a sidebar for my facets(filtering).</p>

<p>So clicking on a filter , the content is changed based on that and the page URL as well , so the sidebar closes.</p>

<p>What I'd like to do , is the sidebar to stay open until the user clicks the X..</p>

<p>I used W3School sidebar tutorial for this , so this is my code : </p>

<pre><code>&lt;div id="mySidenav" class="sidenav"&gt;
  &lt;a href="javascript:void(0)" class="closebtn" onclick="closeNav()"&gt;&amp;times;&lt;/a&gt;
  &lt;a href="#"&gt;About&lt;/a&gt;
  &lt;a href="#"&gt;Services&lt;/a&gt;
  &lt;a href="#"&gt;Clients&lt;/a&gt;
  &lt;a href="#"&gt;Contact&lt;/a&gt;
&lt;/div&gt;

&lt;!-- Use any element to open the sidenav --&gt;
&lt;span onclick="openNav()"&gt;open&lt;/span&gt;
</code></pre>

<p>JavaScript:</p>

<pre><code>/* Set the width of the side navigation to 250px and the left margin of the page content to 250px */
function openNav() {
    document.getElementById("mySidenav").style.width = "250px";
    document.getElementById("main").style.marginLeft = "250px";
}

/* Set the width of the side navigation to 0 and the left margin of the page content to 0 */
function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
    document.getElementById("main").style.marginLeft = "0";
}
</code></pre>

<p>CSS</p>

<pre><code>/* The side navigation menu */
.sidenav {

    height: 100%; /* 100% Full-height */
    width: 0; /* 0 width - change this with JavaScript */
    position: fixed; /* Stay in place */
    z-index: 1; /* Stay on top */
    top: 0;
    left: 0;
    background-color: #111; /* Black*/
    overflow-x: hidden; /* Disable horizontal scroll */
    padding-top: 60px; /* Place content 60px from the top */
    transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
}

/* The navigation menu links */
.sidenav a {
   font-size: 20px;
   padding:5px 10px 5px 10px;
    text-decoration: none !important;    
    color: #818181;
    background: transparent;
    display: block;
    transition: 0.3s
}

/* When you mouse over the navigation links, change their color */
.sidenav a:hover, .offcanvas a:focus{
    color: #f1f1f1;
}

/* Position and style the close button (top right corner) */
.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

.sidenav .removebtn {
    color: #e9e9e9;
    position: absolute;
    top: 0;
    left: 25px;
    font-size: 20px;
    margin-right: 50px;
}

/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
    transition: margin-left .5s;
    padding: 20px;
}

/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
    .sidenav {padding-top: 15px;}
    .sidenav a {font-size: 18px;}
}
</code></pre>

<p>I saw some solutions including Cookies , but being a noob in JS stuff , i'd like an answer i can understand.</p>

<p>Thank you!</p>