Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to get url query string in jquery sharepoint 2013
6203 Views
Introduction 
For example, when creating the sharepoint hosted app the custom properties send through querystring.In that process you need to get query string values by jquery.The example codes follows
Jquery
function getUrlVariable() {/* Function to get query string values */
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = decodeURIComponent(hash[1]);
    }
    return vars;
}

$(document).ready(function () {
var queryVariable = getUrlVariable();/* Assign function to variable */
eListName = decodeURIComponent(queryVariable["listName"]);/* Getting the values */
eEventTitle = decodeURIComponent(queryVariable["eventTitle"]);
});
Another way
// Function to get the URL parameters
function getURLParameter(name) {
    return decodeURI(
          (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [,
null])[1]
    );
}
$(document).ready(function () {
hostweburl = decodeURIComponent(getURLParameter("SPHostUrl"));
appweburl = decodeURIComponent(getURLParameter("SPAppWebUrl"));
});
Best Lessons of "Microsoft Sharepoint 2013"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details