I’m experiencing a situation in the Custom Portal where the browser is holding filter values when I close the portal and return later. These values are being passed to other pages/dashboards and causing usability issues. Is there a way to prevent local storage from holding url filter parameters after leaving and returning to the portal?
This can be done with javascript in an HTML block on the page(s) where you want the filters to be reset. Here is an example script that removes values for a local storage variable named zuar.cp.appliedFilters:
<script>
var localVariableFilter = "zuar.cp.appliedFilters"; // local storage variable name
var filters = localStorage.getItem(localVariableFilter).replace(/['"]+/g, ''); // get local storage variable / remove all double quotes
// when local storage value exists, clear value(s) and refresh page without parameters
if(filters) {
localStorage.removeItem(localVariableFilter);
window.location.replace(window.location.href.split('?')[0]);
}
</script>
1 Like
@benzuar Is there a reason for all the extra JavaScript logic?
You can simply do this to remove the filters in local storage:
localStorage.removeItem("zuar.cp.appliedFilters");
For example, a filter is set in the Custom Portal: type=page-nav
localStorage.getItem("zuar.cp.appliedFilters");
"\"type=page-nav\""
localStorage.removeItem("zuar.cp.appliedFilters");
undefined
localStorage.getItem("zuar.cp.appliedFilters");
null
Setting a new filter in the Custom Portal recreates the zuar.cp.appliedFilters
key in local storage.