I am loading a page in to a parent page using the load() function but I am also passing values in a URL string of the loaded page.
It's pretty straight forward; where I am having an issue is on the page that that is loaded the windows.location function only sees the parent url.
How can I or what can I use to see the loaded URL string instead of the parents URL string?
code example of page being loaded in to parent page:
$('.MEDHISTRODATA').load('MedicalHistoryInit.html?AGE='+a+'&DOE='+d+'&PATIENTID='+p);
I am using this function to extract the URL params from the URL string:
function GetURLParameter(sParam){
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++){
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam){
return sParameterName[1];
}
}
};
To get a URL parameter by name, you can also use RegExp:
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '='
+ '([^&;]+?)(&|#|;|$)').exec(location.search) ||
[, ""])[1].replace(/\+/g, '%20')) ||
null
}
So, to call it on load:
window.onload = function init() {
var param_age = getURLParameter('AGE');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.