Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-18
3
Medium Priority
?
3,282 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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-…
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…

636 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