Online Express form reload

Options
I was recently asked to add an Online Express donation page to my Single Page Application.  It works great the first time you go to the donation view, but in all subsequent visits the form's javascript does not execute and you have to refresh/reload the site.  Because this is a SPA when you leave the donation view the form is dropped from the DOM.  I then use the code below to also remove the javascript file and the load function.


I used the following code in the donation view to load/reload the form


                        var elm = document.getElementById("EmbeddedDonationsScript");

                        if (elm !== null) {

                            var jqEl = angular.element(elm);

                            jqEl.remove();

                            if (typeof window.bboxInit === "function") {

                                window.bboxInit = null;     // because it is still in memory

                            }

                        }

                        window.bboxInit = function () {

                            bbox.showForm(embeddedKey);

                        };

                        elm = document.createElement('script');

                        elm.id = "EmbeddedDonationsScript";

                        elm.async = true;

                        elm.src = embeddedURL;

                        document.getElementsByTagName('head')[0].appendChild(elm);


I think there is more that needs to be removed from memory before the form is reloaded.  Thoughts?
Tagged:

Categories