window.changeCFI = function(cfi) {    
    let searchParams = new URLSearchParams(window.location.search);
    
    let path = window.location.pathname + '?q=' + searchParams.get('q') + '&goto=' + cfi;
    window.history.pushState(path, window.document.title, path);
};

jQuery(document).ready(function () {
    window.addEventListener('message', (event) => {    
        if (event.data.type === 'urlChangeEvent') {// && event.target.origin === 'http://iucbenikimk2.con.mkz-lj.si') { 
            let path = window.location.pathname + '?goto=' + event.data.url;
            window.history.pushState(path, window.document.title, path);
        }
        else if (event.data.type === 'redirectEvent') {// && event.target.origin === 'http://iucbenikimk2.con.mkz-lj.si') { 
            window.location.href = event.data.redirectUrl;
        }
        else {
          console.warn('Message type unrecognized and from untrusted origin: ', event.target.origin);
        }
    }); 
});