简体   繁体   中英

How can i remove script tag, which is inside html

i am trying to remove this script tag which is in html, it is used for google analytics, i want to this script to be removed when used does not accept cookies.

<script>     
var _gaq = _gaq || [];
         _gaq.push(['_setAccount', 'UA-46776072-1']);
         _gaq.push(['_setDomainName', 'av.gov.mk']);
         _gaq.push(['_trackPageview']);

        (function () {
             var ga = document.createElement('script'); ga.type = 
        'text/javascript'; ga.async = true;
             ga.src = ('https:' == document.location.protocol ? 'https://ssl' 
         : 'http://www') + '.google-analytics.com/ga.js';
             var s = document.getElementsByTagName('script')[0]; 
        s.parentNode.insertBefore(ga, s);
         })();
     };
</script>

Put the GA script in a function that will be called after accepting cookies.

 function startGA(source) { document.getElementById(window.event.srcElement.id).style.display = "none"; alert("Google Analytics script will be rendered now!") var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-46776072-1']); _gaq.push(['_setDomainName', 'av.gov.mk']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); } 
 <input type="button" id="acceptCookies" value="Accept Cookies" onclick="startGA(this)" /> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM