Solved

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

Posted on 2004-08-18
3
3,263 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular service to share objects between controllers 1 15
https://github.com/willowsystems/jSignature 11 50
Is there a way to use PhantomJS on a shared server? 4 16
Jquery 10 19
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'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

776 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