-1

Possible Duplicate:
How to get the value from URL Parameter?

I have this URL: http://example.com/photos/5062d95d-13e8-ceb8-bb35-5891b62a3418/?id=872364876

And I have this javascript code:

if (sssssssssss) {
    window.location = "http://example.com/s/1525";
} else {
    location.replace('http://example.com/id=');
}

I need to fill the id value from the GET parameters in the else section. Any ideas?

Philipp Maurer
  • 2,480
  • 6
  • 18
  • 25
user1614240
  • 115
  • 2
  • 7

2 Answers2

1

Here is an example of how to get variables from a url using javascript

function getUrlVars() {
     var vars = {};
     var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
          vars[key] = value;
     });
     return vars;
}

Source: http://papermashup.com/read-url-get-variables-withjavascript/

David
  • 2,053
  • 2
  • 16
  • 26
Sherlock
  • 5,557
  • 6
  • 50
  • 78
0

Check this code

var start= location.href.indexOf('id=');
var id= location.href.substring(start+ 3, location.length- 1);
Amir
  • 770
  • 8
  • 21