Forum

Thread tagged as: Question, Problem, Error

Root Directory JavaScript Issue

Hi,

I am using the 'sidr' plugin for the mobile navigation on my site, where it works perfectly for top level pages - but not on any subpages, e.g. my index.php file located in the /solutions/ directory.

Each page is linking to the same header.php file which further links to the relevant .css and .js files. Within the header.php file, each links goes to the root folder before the relevant css and js folders. This works absolutely fine for the css but not for the JavaScript, which has lead me to believe there is a path issue with locating the root folder.

If I duplicate the js folder and place it within my subfolders, e.g. /solutions/, then it works fine - but of course this results in an untidy directory.

I've used developer tools in Chrome in the console tab and there are no JavaScript issues being displayed.

Thanks in advance, J

Darren Cusdin

Darren Cusdin 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Start the path to your JavaScript with a / - so "/script/myjs.js" and not "script/myjs.js".

This makes it root relative therefore correct always from the root of your site.

Hi,

I have done this for each path. The links within the header.php file have no trouble locating the root directory, as it is working for the top level pages, it's just that no JavaScript files are functioning on lower level pages.

Each page is using the exact same header.php file as the css files/folder works perfectly.

Thanks, J

Drew McLellan

Drew McLellan 2638 points
Perch Support

This sounds more like a front-end problem than a Perch question to me.