1
http://h3gsat.altervista.org/DettagliCompleto.php?id=4567

I tried to take the id parameter, but I failed. I have to make this work in javascript (jquery) not php, but I don't know how I can do.

Loïc Faure-Lacroix
  • 13,220
  • 6
  • 67
  • 99
Boomer
  • 57
  • 5

2 Answers2

1

Try this code snippet:

$.urlParam = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
}

// http://h3gsat.altervista.org/DettagliCompleto.php?id=4567
var value_of_id=$.urlParam('id');        // 6

console.log(value_of_id);

Here is demo jsFiddle

EDIT: Pure javascript solution

function urlParam(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
}

// http://h3gsat.altervista.org/DettagliCompleto.php?id=4567
var value_of_id=urlParam('id');        // 6

console.log(value_of_id);
Ravi Dhoriya ツ
  • 4,435
  • 8
  • 37
  • 48
0
$(function(){
  var str = $(location).attr('href');   
  alert(str);
  var myString = str.substr(str.indexOf("?id=")+4);
  alert(myString);


});
Rohit Batham
  • 1,238
  • 1
  • 9
  • 13