Search code examples
javascripthtmlpage-refresh

On a page with a meta refresh (with time=0 seconds) run the analytics javascript in the <Head>?


If I have the Google Analytics .js call at the end of the tag, and I have a meta refresh tag (refresh in 0 seconds) to redirect the page (to another site), will the .js run OK every time or is there a chance the page will somehow redirect before the .js runs?

(My understanding is that the .js essentially runs asynchronously so the answer should be Yes, the .js will always run. But wanted to check.)


Solution

  • firstly look time=0 seconds,so, it may/may not cause an execute , probably 0th chance (No chance) the browser should reload the current page in 0 seconds

    and some Drawbacks to Using Meta Refresh Tags

    Meta refresh tags have some drawbacks:


    Meta refresh redirects have been used by spammers to fool search engines. So search engines remove those sites from their database. If you use a lot of meta refresh tags to redirect pages, the search engines may decide your site is spam and delete it from their index. It’s better to use a 301 Server Redirect instead.

    If the redirect happens quickly (less than 2-3 seconds), readers with older browsers can’t hit the “Back” button. This is a usability problem.
    If the redirect happens quickly and goes to a non-existant page, your readers may get stuck in a loop without seeing any content other than a 404 page. When this happens, most people simply give up and leave rather than trying to figure out where you were trying to take them.
    Refreshing the current page can confuse people. If they didn’t request the reload, some people can get concerned about security.

    why wint you use javascript with a time out?

        <script language=”javascript” type=”text/javascript”>
       setTimeout(function () {
           window.location.href = "tea.html"; //will redirect to your blog page (an ex:                  tea.html)
        }, 2000); //will call the function after 2 secs.
        </script>