I am working on a logic where I want user to be redirected to a particular page if JavaScript is not enabled. I have put a meta-tag which will refresh every few seconds and if JavaScript is enabled and I want to use JavaScript to remove that element.
I have tried many things but I have been unsuccessful in removing the tag. Also I tried to empty the content of the tag but it still redirects.
Is there any other way to deal with this issue?
I am posting some code for you to take a look, I just grabbed it from the web but seems to be emptying the contents when I debug through the code:
var m = $('meta');
for (var c = 0; c < m.length; c++) {
m[c].parentNode.removeChild(m[c]);
m[c].content = '';
}
I am also open to a server side solution but the client does not send much information such as if javaScript is enabled or not…….
Try this:
It certainly depends on how soon your jQuery code executes and how soon your refresh triggers…
Update: The above method does not work. Even though the meta element is removed from the DOM, the browser still executes the refresh.
Live demo: http://www.ecmazing.com/misc/test-removing-meta-element/
I believe you should also be able to do this:
So, if you wrap your meta element in a NOSCRIPT element, it should only be parsed if JavaScript is disabled.
Read about the NOSCRIPT element here: https://developer.mozilla.org/en/HTML/Element/noscript