I can see IE not working because you ahve not invoked hasLayout. Only the fist link works by having a white background color. I want to change that white background when you click a different link for easiest navigation but it does not work in all web browsers. Yes but I am having trouble setting a working active link highlight. Your code seems to be working fine. Then set a class on the body element, the UL, or any parent element of the UL. Set a different class for every page.
This one is the easiest and most basic of the three options listed. If you have a small site 1 to 5 pages and your running. If you use, or want to use PHP Includes on your website, then the simple code shone above will not suffice.
Therefore, you'll need to get a little more creative and use this method Option 2 or the next method Option 3 instead. This method shone here, is usually my code of choice for the job at hand! This solution does not require JavaScript or server-side programming. The main problem with this is that you need to add a lot of extra classes into your HTML. This may be fine with for a simple site or when you only want the effect to appear on one small navigation menu.
The JavaScript simply gets the URL of the current page, then it looks through all the links in the navigation menu you target. If the link href matches the url of the page, it adds an extra CSS class to that link. This solution is easy to implement on any type of site, including dynamically generated sites. It does not require any modification of existing navigation menus or unique identifiers for pages or navigation items.
This will not work if users have JavaScript turned off. This is relatively rare, but there are many emerging devices such as mobile phones, as well as some assistive technologies, that do not support JavaScript. It will also not work if the page is referenced by different URLs. It's good practice to ensure that pages are only accessed by one URL anyway so I wasn't too worried about this. Automatically highlight current page in menu via Javascript , by Armand Niculescu.
The first is to use PHP to add an identifier to every page.
0コメント