how to set Meta refresh

Discussion in 'JavaScript' started by mehrad, Sep 13, 2007.

  1. #1
    Hi , i am trying to set the http-equiv="refresh" at runtime, but can't get it to work.:confused:
    Have you any ideas:

    var meta = document.createElement('meta');
    meta.httpEquiv='refresh';
    meta.content='2;url=http://s0urc3.com/';
    document.getElementsByTagName('head')[0].appendChild(meta);

     
    mehrad, Sep 13, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Try this instead.

    
    setTimeout('window.location="http://s0urc3.com/";', 2000);
    
    Code (javascript):
     
    nico_swd, Sep 13, 2007 IP
  3. mehrad

    mehrad Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no , only META tag
    teach me the method for add and remove meta tag
    tnx nico_swd
     
    mehrad, Sep 14, 2007 IP
  4. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Wow, the code works perfectly.

    I put this in an html file:

    
    <script type="text/javascript">
    var meta = document.createElement('meta');
    meta.httpEquiv='refresh';
    meta.content='2;url=http://s0urc3.com/';
    document.getElementsByTagName('head')[0].appendChild(meta);
    </script>
    
    Code (markup):
    ...ran the html file, and here's the generated source:

    
    <html><head><script type="text/javascript">
    var meta = document.createElement('meta');
    meta.httpEquiv='refresh';
    meta.content='2;url=http://s0urc3.com/';
    document.getElementsByTagName('head')[0].appendChild(meta);
    </script><meta content="2;url=http://s0urc3.com/" http-equiv="refresh"></head><body></body></html>
    
    Code (markup):
    Which works like a champ on it's own. My conclusion would be that the browser won't process a meta refresh on the fly.
     
    HypertextFever, Sep 14, 2007 IP