I have string as page url like this: - artist.php?id=6 or album.php?id=23 I want to get that value of id how to get that in javascript.
            Asked
            
        
        
            Active
            
        
            Viewed 110 times
        
    0
            
            
        - 
                    I want values in javaScript. – Shashank Dubey Feb 07 '20 at 04:49
- 
                    You want id from window url or just from a string ? – Nipun Jain Feb 07 '20 at 04:53
- 
                    just from a string if possible – Shashank Dubey Feb 07 '20 at 04:55
1 Answers
0
            You should try this
In JavaScript you can get values from URL of any param using a function that in below.
$(document).ready(function () {
    var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = window.location.search.substring(1),
                sURLVariables = sPageURL.split('&'),
                sParameterName,
                i;
        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
            }
        }
    };
    var id = getUrlParameter('id');
});
I know it was long code but using this method you can get values of any param.
var id = getUrlParameter('id');
var anyparam = getUrlParameter('param_name');
 
    
    
        Vinay Kaklotar
        
- 424
- 4
- 11
