vrghost
vrghost

Reputation: 1224

java script to press button

Have a nice little solution which basically allows the user to Accept or Reject the websites cookie policy.

The library I'm using (cookies-EU-Banner) http://alex-d.github.io/Cookies-EU-banner/ and the library seems to go on form feed. So basically recognises if Reject or Accept have been pressed that way. This runs outside of Angular. The two buttons looks as follows

<div id="cookies-eu-banner" style="display: none;">
    By continuing your visit to this site, you accept the use of cookies by Google Analytics to make visits statistics.
    <a href="./en-savoir-plus.html" id="cookies-eu-more">Read more</a>
    <button id="cookies-eu-reject">Reject</button>
    <button id="cookies-eu-accept">Accept</button>
</div>

However, I moved the href for additional information over to a angular modal to display the policy, but here comes my problem. The modal will return a accept or reject. But is there a way I can get angular to "set" the cookies-eu-reject or cookies-eu-accept to pressed based on feedback from the modal?

Preferably I do not want to change the npm package.

Upvotes: 2

Views: 97

Answers (1)

azium
azium

Reputation: 20624

In your modal's button handler, find the cookies button you want to click and call its click function. You can see how they're doing it https://github.com/Alex-D/Cookies-EU-banner/blob/master/src/cookies-eu-banner.js

var acceptButton = document.getElementById('cookies-eu-accept')
acceptButton.click()

Upvotes: 1

Related Questions