I have a link that loads a page and calls a javascript function on click. Problem is the javascript function can't finish before the page redirects. Is there anyway to ensure it does ?
You will notice there's an alert()
that is commented out in the javascript function, and if I uncomment it, the function is able to complete. However, I obviously don't want an alert popup to actually take place.
Here is the link :
<a href="p.php?p=$randString&s=$postCat" onclick="setYSession();">
Here is the javascript function that can't finish in time :
function setYSession() {
var YposValue = window.pageYOffset;
$.get('yPosSession.php?yValue=' + YposValue);
//alert(YposValue);
return false;
}