Monday, September 28, 2015

SharePoint Read values from query string parameter


You will always be wanted to read Query string parameter values using javascript in SharePoint 2013 due to the App models.
I was digging internal files of SharePoint 2013 for an issue and accidentally found out inbuilt javascript function "ReadQueryParam" to read query string parameter values.

You can make use of it. No need to write custom javascript/jQuery functions. If you are not able to call it then copy and paste the below SharePoint's javascript inbuilt function in your application (either in .js file or in your page).

function ReadQueryParam(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var results = (new RegExp("[\\?&]" + name + "=([^&#]*)")).exec(window.location.href);
    return (results == null) ? "" : results[1];
}






0 comments:

Post a Comment