nicholasruggeri/cookies-enabler

TripAdvisor badge not enabled

Closed this issue · 7 comments

Hi!
I'm using you script and it works really great, but it seems that TripAdvisor badge does not become active when scripts.get() inject script tag.
Do you have any suggestion about that?
Thx!

Tripadvisor's badge script uses document.write, appending it after the DOM is ready is just not gonna work. As a workaround I included postscribe and then edited the scripts get function like this:

            for (i = 0; i < n; i++){
                if (scripts[i].hasAttribute('data-ce-src')) {
                    postscribe(scripts[i].parentNode, '<script src="' + scripts[i].getAttribute("data-ce-src") + '"></script>');
                } else {
                    s = document.createElement('script');
                    s.type = 'text/javascript';
                    for (y = 0; y < scripts[i].attributes.length; y++) {
                        attrib = scripts[i].attributes[y];
                        if (attrib.specified) {
                            if ((attrib.name != 'type') && (attrib.name != 'class')){
                                s.setAttribute(attrib.name, attrib.value);
                            }
                        }
                    }
                    s.innerHTML = scripts[i].innerHTML;
                    documentFragment.appendChild(s);
                }
            }

Thank you qbitweb!
Your workaroung is working, but TripAdvisor badge does not appear when I press "ok", I have to reload the page to see it.
Do you think there is any chance to make it will appear as soon as I press "ok"?
Thank you again

To reload a page after ok.

COOKIES_ENABLER.init({

onEnabled: function(){ location.reload(); }

});

Thx biapar, but I don't want to reload the page after "ok": I want precisely not that.
I'd like that TripAdvisor badge start after "ok" without reloading the page.

It could be that the badge script attaches the creation on window load and when cookies are already accepted the scripts loads before the event and the badge renders just fine, while if cookies are disabled and you click ok on the cookies_enabler banner the window load event already happened so the badge is not rendered.

You could try to manually trigger window load after pressing ok but it's a bit dirty and could cause other stuff to break.

I added the workaround by @qbitweb in the branch feature/fixReleaseV1.2 . If you find any script that uses document.write, let us know se we can put them in the readme and demos.

Postscribe workaround included in the last version 0.1.3.