I have read this post 1 and the answer was very helpful. I have also read post 2 because I have a similar implementation which was helpful too.
I created two buttons elements using JavaScript which is supposed to navigate/open a folder in the browser (similar to how it's advised to do in Post1 above).
This is how my buttons inside my list-group-items looks like in my page:
The container above is populated by this JS function upon a successful AJAX response (similar to post 2 link above):
function upon_success(data) {
event.preventDefault();
//..
let button1 = '<button class="btn btn-sm btn-primary my-2 my-sm-0 teButton" type="submit" value='+args[1]+'><i class="fa fa-download"></i> TE Log </button>';
let button2 = '<button class="btn btn-sm btn-primary my-2 my-sm-0 ueButton" type="submit" value='+args[2]+'><i class="fa fa-download"></i> UE Log </button>';
$("#bottomContainer").append('<a class="list-group-item list-group-item-light py-0 ">'+'Test case : '+args[0]+'<span class="pull-right">'+button1+' '+button2+'</span></a>');
//..
}
this.value
below has a network path and already has two // on it. I only need to add 1 more /. Right now it doesn't open a network path or even a local directory on the browser.
// jQuery for button 1. This is supposed to open a folder in browser where the files are.
$(document).on("click",".teButton",function (){
var log1 = "file:/"+this.value;
document.getElementById("debug").innerHTML = log1 // FOR DEBUG PRINTING.
// window.location.href = log1 // Why?
// window.location.href = 'file:///C:\TestPC\Log_Database\Lab'
// window.location.href = 'file:///C:\TestPC\Log_Database\Lab\something.txt'
window.location.href = 'file:///C:\Utils'
});
//jQuery for button 2.
$(document).on("click",".ueButton",function (){
var log2 = "file:/"+this.value;
window.location.href = log2
});
Here is my js.fiddle
I have two questions:
- Why isn't my browser opening the folder path/tree when I press/click the button. (If you look at the image I have attached above, you could see the path I am trying to open, which I have printed it. I used file:/// with 3 backslashes)
The error from console says: "Not allowed to load local resource: file:///C:/Dropbox"
- How do I actually download a single file when I click on a button? This is a separate need for another button. (should go to Downloads folder of browser)