Thursday, August 4, 2016

Retrieve Query String Value from Sharepoint using Javascript

If you want to retrieve the values passed via Query String from a SharePoint URL , please use the below function . You can add it to any script editor , content editor web parts or visual web parts .


For example , I have a Query String say ID, and I want the value passed to it , I can call my method as follows.


<script>
$(document).ready(function() {
var ID= getParameterByName('ID'); 
//ID will return the Query string value
alert(ID);
});






function getParameterByName(name,url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}


</script>

No comments:

Post a Comment

Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...