Javascript/HTML Question

Posted:
in Genius Bar edited January 2014
Is there a way to redirect from one page to another using Javascript or HTML? I know how to do it with a Perl CGI script, but the web server doesn't support CGI scripts (at least for free hosting!!).



My internet programming knowledge is pretty basic, so I appreciate any help.

Comments

  • Reply 1 of 4
    I do not believe it is possible with JavaScript, however, there is a really simple way to do it. First off, you could do it with .htaccess, but free hosting probably does not support it. .htaccess is probably the cleanest way, if I am interpreting the question properly.



    To do it with HTML, you want to use a <meta> element. This tag should be placed inside of the <head></head> element.



    Code:


    <meta http-equiv="refresh" content="10;url=http://www.yoursite.com/newpage.html">;









    In the <meta> element, you have two variables: http-equiv and content. The <meta> element is somewhat robust, so instead of explaining what these attributes can do, I will explain what they are doing here. Http-equiv is set to refresh, which means it will refresh the page based on the variables defined in the content attribute. In content the first number is how long until the page refreshes. This is not a number of seconds. The semi-colon allows you to define a second variable, and in this case, the new page that it will refresh to. If no URL is defined, it will simply refresh the current page at an interval.
  • Reply 2 of 4
    acollinsacollins Posts: 60member
    Perfect!! That is exactly what I was looking for. Thanks so much.



    I wish I could have it redirect without loading the page first (I have the content set to 0, but it still loads the page, then redirects), but this works fine for free hosting that doesn't allow me to write my own CGI scripts.



    Regards,

    Andrew
  • Reply 3 of 4
    Andrew,



    Well, if your hosting provider does in fact support .htaccess, why don't you come back here and let me know. By writing a redirect into a .htaccess file, no page has to load as the redirect is handled by the Apache web server itself. You can also do a lot of other cool stuff with .htaccess too, but that is another story for another time...



  • Reply 4 of 4
    gargoylegargoyle Posts: 660member
    Code:




    <script>

    top.location = 'www.apple.com';

    </script>





Sign In or Register to comment.