-3

I want to get parameter from url. Following is my url. I wnt to get "uid" parameter from my url.

http://localhost:8080/mydemoproject/#/tables/view?uid=71
Rahul
  • 131
  • 3
  • 10
  • `window.location.search` will contain `?uid=71` - hope that helps - oops, sorry, no ... `window.location.hash` will contain `#/tables/view?uid=71` – Jaromanda X Feb 28 '18 at 07:30
  • https://davidwalsh.name/query-string-javascript – Chandra Shekhar Feb 28 '18 at 07:32
  • Hi, welcome to SO, please read the [tour] and [ask]. You might also like to read this https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users – freedomn-m Feb 28 '18 at 07:35
  • Literally: https://stackoverflow.com/search?q=How+To+get+url+parameter+from+url+in+jquery%3F gives you the answer. – freedomn-m Feb 28 '18 at 07:38

3 Answers3

0

Try it:

window.location.href.split("=")[1]
Hanif
  • 3,739
  • 1
  • 12
  • 18
-1

Try solving these problems with RegEx

let myURL = window.location.href; // "http://localhost:8080/mydemoproject/#/tables/view?uid=71"
let myRegexp = /uid=(\d*)/i;
let match = myRegexp.exec(myURL);
if (match !== null) {
  console.log(match[1]); // 71
}

A condensed version would look like this

let match = /uid=(\d*)/i.exec(window.location.href);
let uidValue = (match !== null ? match[1] : undefined);
console.log(uidValue); // 71
arthurDent
  • 818
  • 9
  • 13
  • url should be static? and shouldnt change? also the parameter should be same always? evrytime he should use different functions to get different parameters? – Sindhoor Feb 28 '18 at 07:44
  • Why do you downvote every answer? This answer is as legit as your answer is. The question was how to detect the uid parameter not how to detect any parameter. – arthurDent Feb 28 '18 at 07:58
-1

On page load call the function "get_param('uid');" And paste this code into your document.

<script type= "text/javascript" >

    function get_param(param) {
        var vars = {};
        window.location.href.replace(location.hash, '').replace(
        /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
        function (m, key, value) { // callback
            vars[key] = value !== undefined ? value : '';
        }
    );
    alert(vars[param]);
    }
</script>
S K
  • 442
  • 3
  • 5
C.Abrar
  • 21
  • 6