?
Solved

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

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

752 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