JavaScript: Redirecting URL

JavaScript: Redirecting URLWhenever you want to generate dynamic pages you often have to resort to using some server side scripting language such as PHP or ASP.

But let us assume that there are only three or four pages that could be chosen from a drop-down menu (a combo-box). The following procedure helps you create a JavaScript-supported drop-down menu.

First the form:

<form name=="pages">
<select name=="pg_choice" onChange=="javascript: take_there();">
<option value=="no_page">Select a page to go to...</option>
<option value=="pg1.html">Page 1</option>
<option value=="pg2.html">Page 2</option>
<option value=="pg3.html">Page 3</option>
</select>
</form>

This form presents to you three choices of pages. In its onChange attribute we decide what function to call to be re-directed to the respective page. And now the JavaScript (note that I have inserted a dot between < and script so that your email reader doesn't object to the presence of an embedded JavaScript in your message):

<.script language=="javascript">

function take_there()
{
    var destination==document.pages.pg_choice.value;
    var version == navigator.appVersion;
    // sets variable == browser version
    if(destination!=="no_page")
    {
      if (version.indexOf("MSIE") >== -1)
      // checks to see if using IE
      {
         window.location.href=?stination;
      }
      else
      {
         window.open(destination, target=="_self");
      }
    }
}

</script>

Different browsers support different things so quite often you have to check what browser the user is using. The page redirection command is used accordingly.


Related Articles

  • The Basics- JavaScript Tutorial
    To get started with JavaScript, you will want to be able to see the tag that will set a script apart from the HTML. The tags used to begin and end a script are the tags. The opening tag should appear like this
  • Simple Counter & Redirecting & Browser Type
    This is a really 2 file way of making a unique hit counter.
    If you make a new file called counter.txt and just type the number 1 on the first line.
  • Redirection
    Have you changed the navigation structure of your website by moving or deleting pages of your site? If a visitor has the old page bookmarked or comes from a link on another site to it, they will receive a 404 error; page can not be found. Solve this by redirecting the visitor to the new page. The me...
  • 4 Powerful Features of Javascript Programming Language
    In the community of web developers and surfers, Javascript is highly popular as client side scripting language for web browsers. Lets take a look at some of the features of this language.
  • JavaScript Prompts
    Well, lets say you wanted to get somebodys name before they saw the page, and then write their name on your page right before their very eyes... Well, you can do this using a javascript prompt. Heres the command:
  • Introduction to Javascript for Newbies
    Javascript is a client-side programming language whose processing engine is embedded in web browsers like Internet Explorer, Netscape, Firefox, etc. This enables the processing engine to read and interpret web pages that contain the javascript code when browsing
  • Form Validation
    Learn the different ways of validating your form with Javascript.
  • Statusbar Message
    This is a quick, and quite simple tutorial. Now its not html, it uses Javascript. What it does is lets you customize what it says in the status bar usually at the bottom left of your browser. Right now in your browser it should say Infinite Designs.org ..... Heres how to make it do that...
  • Stop Right Mouse Clicks
    Stop people from getting at your source by right clicking on your web page. Sounds good, but doesnt protect you totally, you can never fully protect your work, but it will make it harder.
  • Changing the Background Colour
    Yet another snippet of JavaScript code, folks. This time well be using JavaScript to change a background color with a MouseOver and a mouse click.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.