0

Possible Duplicate:
Get URL parameter with jQuery

I got this url in my browser

http://docs.google.com?k=account&cs=This%20Site&u=https%3A%2F%2Faccess.dev.google.com

I need to check if u paramter is having http or https://access.dev.google.com then perform some action.

Community
  • 1
  • 1
Chitta Sukla
  • 63
  • 4
  • 9
  • 2
    You can use the function mentioned here: http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery – Joe M Aug 02 '12 at 05:45
  • Could be find with: `myhref.replace('%3A%2F%2F', '://').match(/u=(.*)$/g, '$1');` – Alex Ball Aug 02 '12 at 05:51

2 Answers2

0

Could be:

var hr = 'http://docs.google.com?k=account&cs=This%20Site&u=http%3A%2F%2Faccess.dev.google.com'; //window.location.href;

var res = hr.match(/u=(http|https)%3A%2F%2Faccess.dev.google.com/g);
if(res != null) alert('ok');
else alert('not found');

Take a look to jensgram comment. /u= should be: [?&]u=

Alex Ball
  • 4,404
  • 2
  • 17
  • 23
  • 2
    Consider prefixing the regex with `[?&]`, i.e., `/[?&]u=` in order to only match the `u` parameter, not `u`. – jensgram Aug 02 '12 at 06:11
0

Here's a lovely non-regex version.

var path = window.location.pathname;
//assuming you want the path for http://docs.google.com?k=account&cs=This%20Site&u=https%3A%2F%2Faccess.dev.google.com


if(path.substring(path.indexOf('u='​)+2, path.indexOf('u=')+7) == 'https') {
    //execute if https, or change to +2, +6 for http
}​​​​​​​​​

I don't know if that's what you're looking for exactly, but it was worth a shot.

Chad
  • 5,308
  • 4
  • 24
  • 36