@@ -212,12 +212,23 @@ <h1>MDN Browser Support Timelines</h1>
212212}
213213
214214function updateUrlHash ( filePath ) {
215- history . pushState ( null , '' , `#${ filePath } ` ) ;
215+ if ( filePath ) {
216+ history . pushState ( { filePath } , '' , `#${ filePath } ` ) ;
217+ } else {
218+ history . pushState ( { filePath : null } , '' , window . location . pathname ) ;
219+ }
220+ }
221+
222+ function clearDisplay ( ) {
223+ document . getElementById ( 'search-input' ) . value = '' ;
224+ document . getElementById ( 'timeline' ) . innerHTML = '' ;
225+ document . getElementById ( 'api-details' ) . innerHTML = '' ;
226+ document . getElementById ( 'suggestions' ) . innerHTML = '' ;
216227}
217228
218229function getHashPath ( ) {
219230 const hash = window . location . hash . slice ( 1 ) ;
220- return hash ? hash : null ;
231+ return hash ? decodeURIComponent ( hash ) : null ;
221232}
222233
223234function setupAutocomplete ( ) {
@@ -469,11 +480,13 @@ <h1>MDN Browser Support Timelines</h1>
469480}
470481
471482// Handle back/forward navigation
472- window . addEventListener ( 'popstate' , ( ) => {
483+ window . addEventListener ( 'popstate' , ( event ) => {
473484 const hashPath = getHashPath ( ) ;
474485 if ( hashPath ) {
475486 document . getElementById ( 'search-input' ) . value = hashPath ;
476487 fetchBrowserCompatData ( hashPath ) ;
488+ } else {
489+ clearDisplay ( ) ;
477490 }
478491} ) ;
479492
0 commit comments