CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: Broken anchor navigation in nightAndDay template  (Read 497 times)

fgm

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +5/-0
Broken anchor navigation in nightAndDay template
« on: 21 Mar 2022, 08:48:22 pm »
While testing the code of the article Day/Night Colour Switching Using CSS3 Variables and Minimal Vanilla JavaScript I have noticed the anchor navigation is broken.

It's due to fauxBody since removing it the navigation works fine. This should be related to this note:
Quote
You cannot style the actual page BODY, and instead have to rely on a “faux body” DIV element. This means some off-the-shelf scripts that try to track the window scroll won’t work, and have to be rewritten to track the scroll position of #fauxBody instead.

Is there any simple method to keep anchor navigation? No other script is used, just the basic browser functionality (Tested with Chrome and Firefox).

I really like the idea to send vanilla HTML to outdated browsers.

This is the test code with the added links:

Code: [Select]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
<meta
name="viewport"
content="width=device-width,height=device-height,initial-scale=1"
>

<!-- don't even bother sending CSS to legacy IE -->
<meta
http-equiv="X-UA-Compatible"
content="IE=9"
>
<!--[if !IE]>-->
<link
rel="stylesheet"
href="nightAndDay.vars.screen.css"
media="screen,projection,tv"
>
<link
rel="stylesheet"
href="nightAndDay.layout.screen.css"
media="screen,projection,tv"
>
<!--<![endif]-->

<title>Night and Day Toggle Demo</title>
</head><body>

<input
type="checkbox"
id="toggle_nightAndDay"
class="toggle rememberState"
hidden
aria-hidden="true"
>

<div id="fauxBody"><div id="fauxInner">
 
<header id="top">
<h1>Night and Day</h1>
<div id="mainMenu">
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<div><nav>
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#submenu">Sub Menu</a></li>
<li><a href="#search">Search</a></li>
<li><a href="#login">Log In</a></li>
<li class="nightAndDay" hidden aria-hidden="true">
<label for="toggle_nightAndDay"></label>
</li>
</ul>
</nav></div>
<!-- #mainMenu --></div>
<a href="#mainMenu" class="mainMenuOpen" hidden aria-hidden="true"></a>
</header>

<main>
<ul>
<li>
<a href="#disadvantages">
Disadvantages
</a>
</li><li>
<a href="#advantages">
Advantages
</a>
</li><li>
<a href="#notes">
Notes
</a>
</li>
</ul>
<!--[if IE]>
<h2 style="color:red; display:block;" hidden aria-hidden="true">
Error, Outdated Browser Detected
</h2>
<p>
<strong style="color:red; display:block;" hidden aria-hidden="true">
You are recieving a vanilla version of this page because your browser is a decade or more out of date. For full / proper appearance, please revisit in a modern browser.
</strong>
</p>
<![endif]-->

<h2 id="toggling">Toggling Your Colour Scheme</h2>
<p>
This demo shows how a simple hidden <code>&lt;input type="checkbox"&gt;</code> combined with a <code>&lt;label&gt;</code> can be combined to toggle the entire colour scheme of your layout via CSS3 variables.
</p><p>
In the main menu above (or in the mobile modal) click on "day mode" or "night mode" to switch between the two states.
</p>
<h3 id="disadvantages">Disadvantages</h3>
<p>
The only major disadvantage being that IE doesn't know what CSS variables are, and that Chakra based Edge can't handle full properties -- like "1px solid #0003" -- as variables. Since Chakra Edge is now dead replaced by a Blink based <em>(aka "chrome-like")</em> version, and IE users really should expect a degraded experience, I think it's time to tell them where to stick it on full 100% support.
</p><p>
<strong>I'm not saying</strong> not to support said browsers, simply feed them a degraded experience. As any good site should use semantic markup, I say just stop feeding them CSS and JS altogether. Easiest way to do that? Use X-UA to tell IE to pretend to be IE9/earlier, which turns on conditional comments.
</p>
<h3 id="advantages">Advantages</h3>
<p>
Most of the heavy lifting is CSS driven, with only the state change of the checkbox being tracked in localstorage by JavaScript.
</p><p>
As it is almost entirely CSS driven, you do not need to play with the JavaScript or the markup to make any changes.
</p>
<h2 id="notes">Notes</h2>
<p>
This page includes the modal dialog function for hamburger menus and a sub-menu/search/login to demonstrate how the colour inherits to those as well. See <a href="https://levelup.gitconnected.com/modal-dialog-driven-websites-without-javascript-16e858615780">my Medium article about modal driven pages</a> for more information about that part of the code.
</p>

</main>

<footer>
<section>
<h2>Night and Day Demo</h2>
Jason M. Knight, September 2020<br>
<em>Released to the Public Domain</em>
</section><section>
<h2>Links</h2>
<ul>
<li><a href="https://medium.com/@deathshadow/day-night-colour-switching-using-css3-variables-and-minimal-vanilla-javascript-a54fa36c550f">Medium article explaining this</a></li>
<li><a href="#"><a href="https://cutcodedown.com/for_others/medium_articles/nightAndDay/nightAndDay.rar">.RAR of this page</a></li>
</ul>
</section>
</footer>

<!-- #fauxInner, #fauxBody --></div></div>

<form id="login" action="#" method="post" class="modal">
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<div><section>
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<h2>Log In</h2>
<div>
<fieldset>
<label>
Username:<br>
<input type="text" name="name" required><br>
</label><label>
Password:<br>
<input type="password" name="pass" required><br>
</label>
</fieldset>
<div class="submitsAndHiddens">
<button>Submit</button>
<!-- .submitsAndHiddens --></div>
</div>
</section></div>
<!-- #login.modal --></form>

<form id="search" action="#" method="post" class="modal">
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<div><section>
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<h2><label for="search_q">Search</label></h2>
<div>
<fieldset>
<input type="text" name="q" placeholder="HTML, CSS, JavaScript, etc..." required>
<button>&#38;#38;#38;#x1F50D;</button>
</fieldset>
<p>
<em>Note this search is just a layout demo, and is non-functional.</em>
</p>
</div>
</section></div>
<!-- #search.modal --></form>

<div id="submenu" class="modal modalMenu">
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<div><nav>
<a href="#" class="modalClose" hidden aria-hidden="true"></a>
<h2>Sub Menu</h2>
<div>
<ul>
<li><a href="#search">Search</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
<li><a href="#">Link 5</a></li>
</ul>
</div>
</nav></div>
<!-- #submenu.modal.menu --></div>

<!-- same for JavaScript, let IE gracefully degrade -->
<!--[if !IE]>-->
<script src="nightAndDay.js"></script>
<!--<![endif]-->

</body></html>
« Last Edit: 21 Mar 2022, 08:52:18 pm by fgm »

xmohamadx

  • Junior Member
  • *
  • Posts: 23
  • Karma: +2/-0
Re: Broken anchor navigation in nightAndDay template
« Reply #1 on: 22 Mar 2022, 06:28:08 pm »
Hi

I tested what you said, and also copied the code you wrote and did open in Firefox and Chrome, It worked fine. there was no broken anchor navigation for me!
And also, I see no reason "fauxBody" breaks the anchor navigation. What he said in the quote is about off-the-shelf scripts which track the "window" scroll, it does not cause any problem for browsers.

fgm

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +5/-0
Re: Broken anchor navigation in nightAndDay template
« Reply #2 on: 22 Mar 2022, 06:41:33 pm »
The anchor links work but back button does not make it go back.

It works fine in this simplified version, or just removing the fauxBody div:
Code: [Select]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
<meta
name="viewport"
content="width=device-width,height=device-height,initial-scale=1"
>
</head><body>

<header id="top">
<h1>Night and Day</h1>
<div id="mainMenu">
<div><nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#submenu">Sub Menu</a></li>
<li><a href="#search">Search</a></li>
<li><a href="#login">Log In</a></li>
<li class="nightAndDay" hidden aria-hidden="true">
<label for="toggle_nightAndDay"></label>
</li>
</ul>
</nav></div>
<!-- #mainMenu --></div>
</header>

<main>
<ul>
<li>
<a href="#disadvantages">
Disadvantages
</a>
</li><li>
<a href="#advantages">
Advantages
</a>
</li><li>
<a href="#notes">
Notes
</a>
</li>
</ul>

<h2 id="toggling">Toggling Your Colour Scheme</h2>
<p>
This demo shows how a simple hidden <code>&lt;input type="checkbox"&gt;</code> combined with a <code>&lt;label&gt;</code> can be combined to toggle the entire colour scheme of your layout via CSS3 variables.
</p><p>
In the main menu above (or in the mobile modal) click on "day mode" or "night mode" to switch between the two states.
</p>
<h3 id="disadvantages">Disadvantages</h3>
<p>
The only major disadvantage being that IE doesn't know what CSS variables are, and that Chakra based Edge can't handle full properties -- like "1px solid #0003" -- as variables. Since Chakra Edge is now dead replaced by a Blink based <em>(aka "chrome-like")</em> version, and IE users really should expect a degraded experience, I think it's time to tell them where to stick it on full 100% support.
</p><p>
<strong>I'm not saying</strong> not to support said browsers, simply feed them a degraded experience. As any good site should use semantic markup, I say just stop feeding them CSS and JS altogether. Easiest way to do that? Use X-UA to tell IE to pretend to be IE9/earlier, which turns on conditional comments.
</p>
<h3 id="advantages">Advantages</h3>
<p>
Most of the heavy lifting is CSS driven, with only the state change of the checkbox being tracked in localstorage by JavaScript.
</p><p>
As it is almost entirely CSS driven, you do not need to play with the JavaScript or the markup to make any changes.
</p>
<h2 id="notes">Notes</h2>
<p>
This page includes the modal dialog function for hamburger menus and a sub-menu/search/login to demonstrate how the colour inherits to those as well. See <a href="https://levelup.gitconnected.com/modal-dialog-driven-websites-without-javascript-16e858615780">my Medium article about modal driven pages</a> for more information about that part of the code.
</p>

</main>

<footer>
<section>
<h2>Night and Day Demo</h2>
Jason M. Knight, September 2020<br>
<em>Released to the Public Domain</em>
</section><section>
<h2>Links</h2>
<ul>
<li><a href="https://medium.com/@deathshadow/day-night-colour-switching-using-css3-variables-and-minimal-vanilla-javascript-a54fa36c550f">Medium article explaining this</a></li>
<li><a href="#"><a href="https://cutcodedown.com/for_others/medium_articles/nightAndDay/nightAndDay.rar">.RAR of this page</a></li>
</ul>
</section>
</footer>

<!-- #fauxInner, #fauxBody --></div></div>

<div id="submenu" class="modal modalMenu">
<div><nav>
<h2>Sub Menu</h2>
<div>
<ul>
<li><a href="#search">Search</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
<li><a href="#">Link 5</a></li>
</ul>
</div>
</nav></div>
<!-- #submenu.modal.menu --></div>

<!-- same for JavaScript, let IE gracefully degrade -->

</body></html>

xmohamadx

  • Junior Member
  • *
  • Posts: 23
  • Karma: +2/-0
Re: Broken anchor navigation in nightAndDay template
« Reply #3 on: 22 Mar 2022, 10:03:54 pm »
If you mean the back button of the browser, it also works fine for me.

fgm

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +5/-0
Re: Broken anchor navigation in nightAndDay template
« Reply #4 on: 23 Mar 2022, 03:06:33 am »
I tried again and it fails reliably, also tested in a computer with Windows 7 / Firefox 98.

If I remove just the fauxBody div it works perfect.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1054
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: Broken anchor navigation in nightAndDay template
« Reply #5 on: 29 Mar 2022, 03:52:49 pm »
I have absolutely no idea what you mean by "broken", everything in the example works how it should for me in everything I throw at it.

Can you better describe how/what doesn't work? "Broken anchor navigation" is utterly vague. Please explain step by step what you are doing that doesn't work.

Like:

"open the link to the demo page, click on "submenu', the submenu modal opens".

Though you're using a one year old copy of Firefox isn't encouraging, there's nothing there that would/should break in that outdated copy of the browser.
« Last Edit: 29 Mar 2022, 03:56:45 pm by Jason Knight »
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

fgm

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +5/-0
Re: Broken anchor navigation in nightAndDay template
« Reply #6 on: 29 Mar 2022, 04:13:20 pm »
When I click any of the anchor links it works fine but when I press "Back" button it does nothing, so this breaks the in-page navigation for me. If I remove fauxBody div it behaves as expected: when I press Back button after pressing an anchor link it goes to the initial position.

I have tested it in Chromium 99.0.4844.82 and 99.0.4844.84 with no plugins installed.
« Last Edit: 29 Mar 2022, 04:50:35 pm by fgm »

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1054
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: Broken anchor navigation in nightAndDay template
« Reply #7 on: 29 Mar 2022, 09:08:57 pm »
Have you done something silly like click a bunch of the links that are "#" only, thereby filling up the browser history with nothing but empty lijnks?

Or are you triggering the modal dialogs by going "back" and that's your complaint? If you hold down the back button, what does the back-history look like?

Though what do you mean by "initial position"?!?
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

fgm

  • Jr. Member
  • **
  • Posts: 60
  • Karma: +5/-0
Re: Broken anchor navigation in nightAndDay template
« Reply #8 on: 30 Mar 2022, 03:43:17 am »
I've recorded a video, this is what I do just after opening a fresh browser:

https://mega.nz/file/fk9i1BqD#8YD1rA6RypNX63T7vxr6l-QfB4AHaVJDBMO6VQZ9ndg

Back button works as expected only in test2.html

If I keep the back button pressed I see a bunch of 'Night and Day Toggle Demo', I deleted them but it didn't change this behavior. With 'Initial position' I mean the top of the page.

Dunno if I'm doing something stupid but this is, for me, the intuitive way to use the browser and it always worked fine.

 

SMF spam blocked by CleanTalk

Advertisement