Solved

Read URL Parameter using Javascript then pass on Parameter to another URL

Posted on 2004-08-18
3
3,272 Views
Last Modified: 2011-09-20
Hi

My company's server currently cannot use dynamic scripting languages such as PHP, ASP or JSP, etc. (for reasons I won't go into here!). Therefore my only option is javascript.

What I need to do:

Read the URL Parameter ID - example - http://www.myexample.com?ID=1)
Pass into another URL - example - http://www.myexample2.com
and redirect the page to new URL - example - http://www.myexample2.com?ID=1

Is this possible?

Thanks for your time
N
0
Comment
Question by:nelliott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Colosseo earned 125 total points
ID: 11829046
Hi N

This code will check for the existence of a ? in the current url.
If found it will add it to the new url and redirect there

The only problem is that on my server using your example url i get output of

http://www.myexample2.com/?id=1

I think this is because there is no page sepcified. I dont know if that is a problem but if you know the page that you are redirecting to on the site you can use

new_URL = "http://www.myexample2.com/page1.htm" + current_URL.substring(current_URL.indexOf('?'));

<script language="JavaScript">

  // Get the current url
  current_URL = document.location.href;
  // If a ? is in the url
  if (current_URL.indexOf('?') != -1) {
   // Concatenate the new url with everthing after the ?
    new_URL = "http://www.myexample2.com" + current_URL.substring(current_URL.indexOf('?'));
    // redirect tothe new url
    window.location = new_URL;
  }
 
</script>

Cheers

Scott
0
 

Author Comment

by:nelliott
ID: 11829238
Pure genius.

Works like a charm.

Thanks for your time
N
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 11829255
Your welcome, glad its working

Thanks for the Grade

Scott
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question