{"id":8840,"date":"2023-10-18T03:30:20","date_gmt":"2023-10-18T03:30:20","guid":{"rendered":"https:\/\/bonloyalty.com\/?post_type=docs&#038;p=8840"},"modified":"2026-04-05T05:54:15","modified_gmt":"2026-04-05T05:54:15","slug":"bon-loyalty-widget-and-spa","status":"publish","type":"docs","link":"https:\/\/bonloyalty.com\/ja\/docs\/technical\/bon-loyalty-widget-and-spa\/","title":{"rendered":"BON Loyalty\u30a6\u30a3\u30b8\u30a7\u30c3\u30c8\u3068SPA"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"8840\" class=\"elementor elementor-8840\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d0c4223 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d0c4223\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4dd10986\" data-id=\"4dd10986\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-69520584 elementor-widget elementor-widget-text-editor\" data-id=\"69520584\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>BON Loyalty Widget and Single Page Application (SPA)<\/h2><p>One of the issues with SPA (Single Page Application) is the website does not refresh after user authentication (login\/register). Our authentication is running on the server side, and it takes effect only when page is refreshed!<\/p><p>The walk-around code below should help BON Loyalty Widget work well with SPA.<\/p><p>After the customer is authenticated (login\/register) successfully on the website, run the following code snippet to re-initiate our widget to enable the customer authentication together with the BON Loyalty Widget.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">function createjscssfile(filename){\n    var fileref=document.createElement('script')\n    fileref.setAttribute(\"type\",\"text\/javascript\")\n    fileref.setAttribute(\"src\", filename)\n    return fileref\n}\n \nfunction replacejscssfile(oldfilename, newfilename){\n    var allsuspects=document.getElementsByTagName(\"script\")\n    for (var i=allsuspects.length; i&gt;=0; i--){ \/\/search backwards within nodelist for matching elements to remove\n        if (allsuspects[i] &amp;&amp; allsuspects[i].getAttribute(\"src\")!=null &amp;&amp; allsuspects[i].getAttribute(\"src\").indexOf(oldfilename)!=-1){\n            var newelement=createjscssfile(newfilename)\n            allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])\n        }\n    }\n}\n\nwindow.bonRender = false;\nreplacejscssfile(\"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\"<\/pre><p>\u00a0<\/p><p>\u00a0\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>BON Loyalty Widget and Single Page Application (SPA) One of the issues with SPA (Single Page Application) is the website does not refresh after user authentication<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":19,"featured_media":0,"template":"","class_list":["post-8840","docs","type-docs","status-publish","hentry","docscategory-technical"],"acf":[],"_links":{"self":[{"href":"https:\/\/bonloyalty.com\/ja\/wp-json\/wp\/v2\/docs\/8840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bonloyalty.com\/ja\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/bonloyalty.com\/ja\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/bonloyalty.com\/ja\/wp-json\/wp\/v2\/users\/19"}],"version-history":[{"count":6,"href":"https:\/\/bonloyalty.com\/ja\/wp-json\/wp\/v2\/docs\/8840\/revisions"}],"predecessor-version":[{"id":22601,"href":"https:\/\/bonloyalty.com\/ja\/wp-json\/wp\/v2\/docs\/8840\/revisions\/22601"}],"wp:attachment":[{"href":"https:\/\/bonloyalty.com\/ja\/wp-json\/wp\/v2\/media?parent=8840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}