Aureole Posted November 13, 2007 Share Posted November 13, 2007 I've been trying to come up with a solution for times when I need to make a site require Javascript. I'm using a meta tag inside a noscript tag, now here's the thing... I'm trying to use Javascript to write a HTML comment, as meta tags outside of the head aren't allowed and noscript tags outside of the body aren't allowed. I'm basically trying to make it so if you have Javascript enabled the noscript/meta will be commented out thus it will still validate and if you don't have javascript enabled you will be redirected to a page where there is no noscript/meta tag therefore everything validates and everyone's happy. <script type="text/javascript"> document.write('<!--'); </script> <noscript> <meta http-equiv="refresh" content="0;URL=<?php echo SITE_PATH; ?>/nojs.swr3"> </noscript> <script type="text/javascript" > document.write('-->'); </script> This doesn't work, it echoes '); onto the page, I've tried making the ">" into it's html entity counterpart and I tried escaping it with a backslash. Truth is I don't know Javascript, what do I need to do to get this to work? EDIT: Please no lectures on accessibility etc. "You should use Javascript to enhance your site", "Your site shouldn't depend on Javascript"... I know this, I'm just trying to think of a solution for when you absolutely have no other choice but to rely on Javascript. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 15, 2007 Share Posted November 15, 2007 you do not need to comment out the no script tag for this. if you have your meta in your noscript tag; unless javascript is turned off, the meta refresh will not occur. Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 17, 2007 Author Share Posted November 17, 2007 I know this... but it will still show up in the source and will cause my page to not validate, did you read what I said? ??? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted November 17, 2007 Share Posted November 17, 2007 Couldnt you just give it an id and remove it from the dom if js exists <head> <script> (function removeHeader(){ var js = document.getElementById('no_js'); var x = document.getElementsByTagName('head')[0]; x.removeChild(js); }()); </script> <meta http-equiv="refresh" content="0;URL=<?php echo SITE_PATH; ?>/nojs.swr3" id="no_js"> </head> havent tested so i dont knwo if it works Quote Link to comment Share on other sites More sharing options...
emehrkay Posted November 17, 2007 Share Posted November 17, 2007 sorry the original code that I gave you was flawed. However, this method will not work at all as removing the meta does not remove it from the browser's memory <meta http-equiv="refresh" content="20;http://google.com" id="no_js"> <script type="text/javascript"> (function ale(){ var js = document.getElementById('no_js'); var x = document.getElementsByTagName('head')[0]; x.removeChild(js); }()); </script> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 18, 2007 Share Posted November 18, 2007 Aureole, and commenting out a meta tag does validate - yeah, ok, whatever. I know this... but it will still show up in the source and will cause my page to not validate, did you read what I said? ??? If the noscript tag does not validate; your original example sure as heck does not validate. You should have already known that document.write would just write the contents of what you put in it and not html source code. Your trying to use DOM to write source code and that cannot be done. Client side and Server side are two different animals. Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 19, 2007 Author Share Posted November 19, 2007 Well I don't know any Javascript, hence why I asked. Thanks anyhow. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.