I am trying to read a label and append its value as a query string once the user hits the refresh button on their browser. The code I have so far is:
function AppendQueryString() {
var currUrl = document.location;
var trackingNbr = $("#lblTrackingNbr").text();
if (window.location.href.indexOf("?TrackingNumber=") <= 0 && trackingNbr !== null) {
document.location = currUrl + "?TrackingNumber="+ trackingNbr;
}
}
window.onbeforeunload = AppendQueryString();
The problem is, the trackingNbr variable is always null even though the label has the value before I hit refresh. What am I doing wrong or is there a better way of doing this ?
history.pushState