Jump to content

[SOLVED] Why won't this work


Aureole

Recommended Posts

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. :D

 

<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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.