I am currently implementing jstree and I need to be able to click on a file within the tree structure in order to display a PDF file. Below is the relevant code snippet:
$(function () {
$('#tree').jstree({
'core' : {
'data' : {
'url' : function (node) {
return node.id === '#' ? 'assets/ajax_roots.json' : 'assets/ajax_children.json';
},
'data' : function (node) {
return { 'id' : node.id };
}
}
},
$('#tree').on("changed.jstree", function (e, data) {
// this gives the path
var path = data.instance.get_path(data.node,'/');
const url = new URL(window.location.href);
})
In order to clarify my requirement, I would like to append the file path to the URL using JavaScript's URLSearchParams. Currently, I have only managed to achieve this much:
http://somewhere.com/index.html
However, I am aiming for the following format:
http://somewhere.com/index.html/?file=/to/some/dir/filename.pdf
If someone could assist me in getting started with this task, I would greatly appreciate it. Thank you