I have nested .php pages -- for example, 'oneNestedPhpWebPage.php' -- in a subfolder "mysite/theSubfolder".
These pages in the subfolder includes a nav bar .php file which is located in the parent folder:
// this is code inside my nested .php page "oneNestedPhpWebPage.php"
<?php
require_once('../TopNav.php');
?>
This TopNav.php is also being used by webpages in the site's root folder and I have to leave TopNav.php in the root folder.
When I visit the page "oneNestedPhpWebPage.php" all is well initially -- I can see the page. And I can see the TopNav.php nav bar too.
But the TopNav.php page has the following line of code:
<script src="nb.js"></script>
And, like TopNav.php itself, the javascript file "nb.js" is in the site's root folder.
If the TopNav.php is being used by one of my nested .php pages, such as oneNestedPhpWebPage.php -- this nb.js file's javascript functions are not being found when called from the included TopNav.php.
The javascript file nb.js is in the site's root folder, which is one folder above the nested web pages like my "oneNestedPhpWebPage.php"
Now, I'm also using TopNav.php -- my navbar code -- in a bunch of .php web pages in the parent folder of the site -- for example, in my index.php web page in the site's root folder, I have the following -- note the difference here from the similar line of code above:
// this is code inside my index.php page located in the site's root folder
<?php
require_once('TopNav.php');
?>
Here, because my nb.js file is located in the parent folder with index.php, the TopNav.php's calls to javascript functions in nb.js work fine.
So to try to get around this problem, I added 2 lines of code:
this line of code at the bottom of my nested file "oneNestedPhpWebPage.php" :
<input type="hidden" id="nestedBnbPage" value="1" />
And then I tried something I've not tried before, I put this inside TopNav.php:
<script src="nb.js">if(document.getElementById('nestedBnbPage'))this.src="../nb.js";
This did not solve the problem.
I have 53 .php web page files that are located in the nested "mysite/theSubfolder" subfolder. I have more than that in the root folder of the site.
And I need to use the Navbar code in both sets of root-folder pages and nested-folder pages.
And I cannot put the nb.js javascript code inside of TopNav.php.
How can I configure TopNav.php so that, when it's in use by one of the nested web pages, TopNav.php will be able to "find" its nb.js javascript file in the site's root folder?