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>
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