'JavaScript needs to only be called on button click in Rails project
i am unable to make my JavaScript code work as intended. The script should run only the click of the button, but it is running even when page refreshes.
- if params[:id] == "HuckabeeBook"
:javascript
function LoadScript(url) {
var script = document.createElement('script');
script.setAttribute('src', url);
script.setAttribute('async', false);
document.head.appendChild(script);
}
$(function () {
$('#submit_contribution.donate-btn').click(function () {
LoadScript('https://secure.adnxs.com/px?id=1585351&seg=30062567&t=1');
});
});
I think i am missing out something here, any would be appreciated. Cheers
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
