Sergei
Posts: 10
Joined: Wed Mar 04, 2009 12:58 pm

W3C Validation Error for hs.registerOverlay

Hello,

I use closebutton in top right position and it is working fine.

Code: Select all

<script type="text/javascript">
hs.registerOverlay({
        html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
        position: 'top right',
        fade: 2 // fading the semi-transparent overlay looks bad in IE
});
</script>
Meanwhile W3C reports validation error -
Error found while checking this document as HTML 4.01 Transitional!
end tag for element "DIV" which is not open
.... </div>',

Any Idea why and how to sort it?
Many thanks!

Serg
MisterNeutron
Posts: 440
Joined: Sun Aug 18, 2013 11:20 am

Re: W3C Validation Error for hs.registerOverlay

This is a common problem. The validator is trying to validate the code within the <script> tags as if it were active HTML on the page. It's essentially just an error by the validator itself. Surprisingly, even wrapping the code in a CDATA section doesn't seem to cure the problem for that DOCTYPE. That approach does work for XHTML.

One simple solution is to put your page-specific Javascript in a separate config file, then just call it from the page, like:

Code: Select all

<script type="text/javascript" src="../highslide/highslide.js"></script>
<script type="text/javascript" src="highslide.config.js"></script>
The highslide.config.js file would contain:

Code: Select all

hs.registerOverlay({
        html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
        position: 'top right',
        fade: 2 // fading the semi-transparent overlay looks bad in IE
});
But the best solution of all is to ditch HTML 4.01 Transitional, and use HTML5. The HTML and XHTML "transitional" DOCTYPE's were intended to smooth the transition from HTML 3 to HTML 4 - in 1997. It's well past time to let them go! In HTML5, that chunk of code in a <script> tag validates without complaint.
Sergei
Posts: 10
Joined: Wed Mar 04, 2009 12:58 pm

Re: W3C Validation Error for hs.registerOverlay

Thanks for reply

I decided to make specific Javascript in a separate config file, then just call it from the page.
That's eliminated validation error!
I also tested HTML5 solution by changing doctype but it created about 180 new validated errors per page and I have 100s pages so much easy to stay vith 4.01 as long as it works.
MisterNeutron
Posts: 440
Joined: Sun Aug 18, 2013 11:20 am

Re: W3C Validation Error for hs.registerOverlay

Sergei wrote:... so much easy to stay vith 4.01 as long as it works.
Eventually that will sneak up on you. My advice would be to start chipping away at it, piece by piece. You will quickly learn what things to avoid - most of it has to do with deprecated tags. It's not difficult, but if you have a lot of pages, it certainly will take quite a bit of time.

For now, all browsers still support that 20-year-old HTML, but support for it could be dropped at any time, and then you'd be madly scrambling to catch up! :shock:

Return to “Highslide JS Usage”