www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: Meta tag doesn't validate in validator

  1. #1
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    223

    Meta tag doesn't validate in validator

    I'm aiming at 0 errors in the W3C validator on my homepage.
    Right now I'm getting an error:

    'document type does not allow element "meta" here' pertaining to the following code right at the beginning of the body:

    <noscript><meta http-equiv="refresh" content="0; URL=http://4nf.org/bo.php?u=http://4nf.org/" /></noscript>

    see: http://4nf.org/

    (I want a redirect to kick-in in case JavaScript is disabled)

    What's the correct way to do that?


    Thanks in advance and kind regards

  2. #2
    Join Date
    Mar 2011
    Posts
    1,110
    For most <!DOCTYPE>s, <meta> tags are only allowed in the <head> section. Move your code there.

    Generally, I prefer not to automagically send users elsewhere with a <meta> refresh. If a page requires JavaScript, I prefer to issue a warning at the top of the page, give the user a plain link to escape, if necessary, and create any critical action elements with JavaScript instead of plain HTML so that the non-js browsers don't display any controls that won't work for those users.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Feb 2012
    Location
    Bokaro Steel City (Jharkhand), India!
    Posts
    194
    Yes, I also feel the same!

  4. #4
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    223
    Thank you both!

    The code snippet was taken from Facebook. They've got it in the head.
    If I put it in the head, I get 3 errors, due to the noscript tag and the meta tag.
    Noscript, according to W3C should be in the body...

    What do you do with the user, when he clicks the click (the escape).

    Thanks very much!

  5. #5
    Join Date
    Mar 2011
    Posts
    1,110
    An escape route isn't always possible or practical if the entire site relies on JavaScript. Sometimes all you can do is to inform the user of the situation and let them find their own way out. There's no need to take extreme measures for non-js users. Relatively few users run with JavaScript disabled these days - somewhere in the single-digit percentage range from what I see and read. Do your best to accommodate them when you can, and you should be fine. Good luck!
    Rick Trethewey
    Rainbo Design

  6. #6
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,450
    Hi there arvgta,

    have you considered doing it the other way round?

    If you put this in your non javascript page...
    Code:
    
    <script type="text/javascript">
    function init(){
       location.href='http://4nf.org/'
     }
       window.addEventListener?
       window.addEventListener('load',init,false):
       window.attachEvent('onload',init);
    </script>
    
    ...those with javascript enabled will be redirected to your intended location.

    coothead
    Last edited by coothead; 05-06-2012 at 02:50 PM. Reason: experienced a "Senior Moment"

  7. #7
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    223
    Thanks for all your feedback - wow!

    I want to follow the example of Facebook, the snippet was adapted from there and I think they really do a good job for the non-JavaScript audience. I want to do the same, and am quite happy with my architecture.
    All of the tag subtitution is now done in PHP and works well without JavaScript - no worries.

    If I put the snippet in the head:

    Code:
    <noscript><meta http-equiv="refresh" content="0; URL=http://4nf.org/bo.php?u=http://4nf.org/" /></noscript>
    ...I get 3 errors

    If I put it in the body there is only 1 error - pertaining to the meta tag, so I would reckon W3C sees this as a bit cleaner.

    My question is really, if there is any way to get rid of the error.
    (I need and want the redirect, just like Facebook does)

    (Browsers seem to have no problem with the meta tag in the body)

  8. #8
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,450
    Hi there arvgta,

    what do you not like about my suggestion, which produces no validation errors?

    coothead

  9. #9
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    223
    Hi coothead

    your suggestion is much appreciated, would work and is elegant.
    I read it carefully.

    I just don't want to completely overhaul the architecture I'm happy with.

    Your way, which is definitely a more classic way, the "default" page would be for the audience with JavaScript disabled - as I understand. Then in case JavaScript is enabled, I would jump to the "real" full breed page.

    The main problem is, that the first and main URL would be very ugly
    e.g.

    Code:
    http://4nf.org/bo.php?u=http://4nf.org/
    Customers would have to place links to that page, which they surely don't want to...

    If I understood that wrong, please let me know.

    No, I'm following the FaceBook architecture:

    - "Default page" - assume JavaScript enabled
    - in case not - graceful descent to the escape page

    My only worry is how to make the mentioned snippet validate.
    I've been told not to worship the W3C validator too much.
    Maybe I'll have to live with the error...

  10. #10
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,450
    Hi there arvgta,

    what is wrong with making the "non-javascript page" the default page - ( http://4nf.org/ ).

    Then redirect...
    Code:
    <script type="text/javascript">
    function init(){
       location.href='http://4nf.org/your-javascript-page.php';
     }
       window.addEventListener?
       window.addEventListener('load',init,false):
       window.attachEvent('onload',init);
    </script>
    
    coothead

  11. #11
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    223
    Hi Coothead,

    difficult to explain.

    At the end of the day, you'd have to have a close look at what I'm trying to serve:

    http://4nf.org/n.js

    ...and achieve.

    Of course, if you find an improvement or simplification in the architecture, I'd be very grateful!

  12. #12
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    223
    Hold on, I've got an idea Coothead, don't know, if that's what you meant:

    I could do the following. Please note that this is cross-domain:

    (my main client is "Íko Fakt" - http://www.oeko-fakt.de/)

    - Include an unconditional redirect to http://4nf.org/bo.php from that client page
    - Perform all tag substitution in PHP and include your formidable JS-snippet
    - In that snippet redirect back to the client page http://www.oeko-fakt.de/ and enjoy full JS and AJAX functionality!

    What do you think of that architecture? Is it cleaner?


    Thanks very much for the snippet!
    http://4nf.org/ - Ajaxify jQuery plugin

  13. #13
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,450
    Hi there arvgta,

    what I meant was this:-

    instead of having this address for your non-javscript page...

    ...change it to this...


    Then name your your desired destination page, which was http://4nf.org/index.php,
    to let's say, for example, index1.php.

    The script in http://4nf.org/index.php would then look like this...
    Code:
    <script type="text/javascript">
    function init(){
       location.href='http://4nf.org/index1.php';
     }
       window.addEventListener?
       window.addEventListener('load',init,false):
       window.attachEvent('onload',init);
    </script>
    
    The result being that http://4nf.org/ will always take your users to the appropriate page.

    I hope that this now makes sense.

    coothead

  14. #14
    Join Date
    Jan 2009
    Posts
    3,346
    Another thing to keep in mind arvgta, if you are automatically handling the processing with PHP you'll be showing to Google your links you were trying to hide...

  15. #15
    Join Date
    Jan 2011
    Location
    Munich, Germany
    Posts
    223
    Hi Criterion9,

    just in the case of Google, it seems it spiders both the condensed and the elaborate versions...

    Google likes content, I suppose!
    http://4nf.org/ - Ajaxify jQuery plugin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles