How do you redirect a html url to a hash # url

Scripting

Redirecting a HTML Url to a Hash # Url

Overview

I was designing a one page website for a client who asked when the web page is first pulled up can the Gate City (about tab) be the first page the person sees in lieu of the index page when making a call for the index page.

As I mentioned I was designing a one page website which really was a multiple page website with the additional pages of the website acquired using AJAX so the page does not refresh hence a one page website.

A hash url or # url is a url generated by AJAX

An example of a hash url in it's complete form http://examplesampledomain.com/#about

So how do you redirect a html url in this case the index page, to a hash # url AJAX page that needs to populate to be seen and populate from the actual url that carries its populating function that is being redirected to open this AJAX page that theoretically does not even exist.

Place this Javascript Code inside the head of the HTML page you wish to have redirected to an AJAX page without the parentheses the parentheses were added so the Javascript Code would not engage redirecting this article.

(<script type="text/javascript"> 
  // Redirect to "#about" if there is no hash in the URL. 
  if (window.location.hash == '') { 
    window.location.href = 'http://gatecityremodeling.com/#about'; 
  } 
script>)

Because the index page does not have a hash # in it's url and carries this Javascript code inside it's head section it will be redirected to, actually populate the AJAX page you want the index page to be redirected to.

See this javascript code in action at http://gatecityremodeling.com although you request the index page by pressing this url you are redirected to http://gatecityremodeling.com/#about a populated AJAX page NICE!

  • 3 brukere syntes dette svaret var til hjelp
Var dette svaret til hjelp?