3
<meta name="redirection" http-equiv="refresh" 
      content="2;url=http://www.google.com">   

It redirects to google.com after 2 seconds. Instead of 2 seconds to make the redirection after 2 minutes just need to change content="120".

Problem:
The numerical value is configure in Database in minutes (30 minutes),in seconds its (30*60=1800). How to do this calculation and set dynamically the meta tag's content to 1800.

I tried using jquery

var value = "1800;http://wwww.google.com";  
$('meta[name="redirection"]').attr("content", value);  

its not working

jensgram
  • 31,109
  • 6
  • 81
  • 98
JAB
  • 3,546
  • 9
  • 36
  • 39
  • http://stackoverflow.com/questions/2568760/is-it-possible-to-use-javascript-to-change-the-meta-tags-of-the-page –  Apr 26 '12 at 05:15
  • You can create the tag dynamically at the server side – Ramesh Apr 26 '12 at 05:18
  • 1
    Voting to close as not a real question because either it should be done server side (in which case this question doesn't provide any of the necessary detail), or it should be done with JavaScript (in which case RC's link has the answer). – David Wolever Apr 26 '12 at 05:19
  • plz let me know , how to do this on server side – JAB Apr 26 '12 at 05:32

2 Answers2

1

It is possible to create a meta tag client side, e.g. like this:

var foo = document.createElement('meta'), refreshtime = 1800;
foo.setAttribute('http-equiv','refresh');
foo.setAttribute('content',refreshTime+';url=http://www.google.com');
document.getElementsByTagName('head')[0].appendChild(foo);

Or using jquery:

$('<meta http-equiv="refresh" content="'+refreshtime+
     ';url=http://www.google.com"/>')
 .appendTo($('head'));​
KooiInc
  • 119,216
  • 31
  • 141
  • 177
  • nice approach , it does create meta tag inside head , but redirection doesn't happen .. any idea – JAB Apr 26 '12 at 05:42
  • If you're loading a page in an Iframe, it may be restricted by security constraints. See http://jsfiddle.net/KooiInc/LXzVU/ for a working example – KooiInc Apr 26 '12 at 05:49
  • `appendTo($('head';))` contains a `;`. Furthermore the path to jquery (`src="jquery-1.7.1.min.js`) is not a full path. – KooiInc Apr 26 '12 at 06:23
  • Additionally you should use a *full url* for redirecting: `url=http://yahoo.com` – KooiInc Apr 26 '12 at 06:25
1
<html>    
<head>  
<script type="text/javascript">
var refreshTime= 2*2;
    var foo = document.write('<meta http-equiv="refresh" content="'+refreshTime+';url=http://www.google.com">');
</script>

</head>

<body>

Meta tag testing

</body>

</html>

Just found that , it can be also done using document.write

JAB
  • 3,546
  • 9
  • 36
  • 39