I'm trying to get the current directory of the file in Javascript so I can use that to trigger a different jquery function for each section of my site.
if (current_directory) = "example" { var activeicon = ".icon_one span"; }; elseif (current_directory) = "example2" { var activeicon = ".icon_two span"; }; else { var activeicon = ".icon_default span"; }; $(activeicon).show(); ...
Any ideas?
In Node. js, there are two built-in ways to get the current directory. You can either use the __dirname variable or the process. cwd() method to get the current folder.
To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory. The command pwd stands for print working directory.
There are two ways you can get the current directory in NodeJS: Using the special variable __dirname. Using the built-in method process. cwd()
window.location.pathname will get you the directory, as well as the page name. You could then use .substring() to get the directory:
var loc = window.location.pathname; var dir = loc.substring(0, loc.lastIndexOf('/'));
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With