jonno
October 6, 2008, 12:55pm
1
Hello,
I have a system where the results appearing on a page are updated periodically by ajax. For people without javascript enabled this is a problem. I have made my system use a meta redirect by default, and intend to have javascript or prototype disable this on page load so people without javascript get a meta redirect, and people with javascript get an ajax update?
<meta http-equiv=“refresh” content=“15;url=/blah.html”></meta>
Problem is - anyone know HOW to disable the meta redirect through javascript or prototype?
Thanks
Jonno.
<meta http-equiv=“refresh” id=“reload” content="15;url=/
From what I have found, you can’t cancel it. All you can do is create it depending on whether javascript is enabled or not…
I’m not sure whether this is valid, but you “could” use noscript?
<noscript>
<meta http-equiv="refresh" content="10;url=/blah.html" />
</noscript>
jonno
October 6, 2008, 3:54pm
3
yeah i thought of <noscript> but aparently it is only allowed in <body>, not <head>.
JimmyP
October 6, 2008, 6:21pm
4
Simply place this in the HEAD:
<script type="text/javascript">
window.location = '/for/Those/With/JavaScript/Enabled.html';
</script>
Edit:
Also, note that <noscript> does not always work. If the user’s JavaScript is being disabled by a firewall (i.e. before it even gets to the browser) then the <noscript> tags are totally useless…
JimmyP
October 6, 2008, 6:30pm
5
Oh I just realised what you meant… U want to totally disable the meta refresh.
You could try something like this: (I’m not sure it will work though)
var m = document.getElementsByTagName('meta'), l=m.length;
while(l--) {
if(m[l].getAttribute('http-equiv')==='refresh') {
m[l].parentNode.removeChild(m[l]);
}
}
Edit:
If you give the meta refresh tag an ID of “reload” then simply:
document.getElementById('reload').parentNode.removeChild(document.getElementById('reload'));
rpkamp
October 6, 2008, 9:27pm
6
Can you give elements in the HEAD an id???
JimmyP
October 6, 2008, 10:04pm
7
AFAIK There is no problem with doing this.
Jimmy I tried that yesterday and it didn’t work unfortunately.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" media="screen" />
<style type="text/css"></style>
<script type="text/javascript">
window.onload = function() {
var reload = document.getElementById('reload');
reload.parentNode.removeChild(reload);
}
</script>
<meta http-equiv="refresh" content="15;url=/blah.html" id="reload" />
</head>
<body></body>
</html>
JimmyP
October 7, 2008, 8:50am
9
gRoberts:
Jimmy I tried that yesterday and it didn’t work unfortunately.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" media="screen" />
<style type="text/css"></style>
<script type="text/javascript">
window.onload = function() {
var reload = document.getElementById('reload');
reload.parentNode.removeChild(reload);
}
</script>
<meta http-equiv="refresh" content="15;url=/blah.html" id="reload" />
</head>
<body></body>
</html>
Works for me. (tested the code you posted in FF3)
JimmyP
October 7, 2008, 8:53am
10
Oh wait. I see what you mean gRoberts. The actual meta tag is removed from the DOM but the page still refreshes. Eveidently the browser initiates the 15 second refresh as soon as it sees the meta tag and so, even removing it from the DOM will not cancel the refresh…
Chrome, FF3 and IE7/8 redirect to blah.html after 15 seconds for me.
jonno
October 7, 2008, 9:00am
12
thanks for the replies, none seem to work and they all seem to forward. i assume it’s probably not possible then?