Reward Display setup
15 April, 2023Leave a review – Judgeme.io
13 December, 2023BON Loyalty Widget and Single Page Application(SPA)
One of the issue with SPA(Single Page Application) is the website does not refresh after user authenticated(login/register). Our authentication is running on server side and it takes effect only when page refresh!
The bellow walk-around code should help BON Loyalty Widget to work well with SPA.
After customer authenticated(login/register) on website successfully, run the following code snippet to re-initiate our widget to able to authenticate customer together with BON Loyalty Widget.
function createjscssfile(filename){
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
return fileref
}
function replacejscssfile(oldfilename, newfilename){
var allsuspects=document.getElementsByTagName("script")
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute("src")!=null && allsuspects[i].getAttribute("src").indexOf(oldfilename)!=-1){
var newelement=createjscssfile(newfilename)
allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
}
}
}
window.bonRender = false;
replacejscssfile("https://d31wum4217462x.cloudfront.net/app/bon-loyalty.js?v=3.2.0", "https://d31wum4217462x.cloudfront.net/app/bon-loyalty.js?v=3.2.0" + new Date().valueOf()) //Replace all occurences of "oldscript.js" with "newscript.js"