jquery - How do I stop 3rd party cookies? - Stack Overflow

I have written a script in jQuery which takes a web site's source code, goes through it and extrac

I have written a script in jQuery which takes a web site's source code, goes through it and extracts all the forms then displays the HTML on my site. An unexpected side effect of this is there are 3rd party cookies being set, which absolutely cannot happen. The main culprit, from what I can ascertain, are HubSpot images and what is most annoying is it seems I don't even have to output the results on my page for the cookies to appear. This is how I am getting the source code:

let getCode = function(file) {

        $.get(file, formAcc);
    };

    getCode('/source-code.txt');

and then, in the 'formAcc' function:

$('form', code).each(function() {});

So, if I comment out the above function, I don't get cookies, but just having that code, not actually using it to populate accordions on the page, is enough to see the cookies in DevTools. I'm fairly good at JavaScript, but not an expert. I have used 'debugger' to go through the process line by line. The site is built using Tabler and the point where the cookies are set is in a part of the code that comes compiled with that and I don't understand it. I'll post the entire function in case it points to where I'm going wrong.

export function contentAccordions() {

    let formAcc = function(code) {
        
        let formLength = code.match(/<form/g).length;
        
        if(formLength > 0) {

            $('#sc-content-panel').append(
                '<div class="row mb-3">'
                    +'<div class="col-12">'
                        +'<div class="card">'
                            +'<div class="card-body">'
                                +'<div class="accordion-wrapper accordion-parent">'
                                    +'<div class="accordion-title">'
                                        +'<h3>Forms <span class="text-muted">('+ formLength +')</span>'+ moreInfoArrow +'</h3>'
                                    +'</div>'
                                    +'<div class="accordion-body">'
                                        +'<div class="accordion-wrapper acc-main"></div>'
                                    +'</div>'
                                +'</div>'
                            +'</div>'
                        +'</div>'
                    +'</div>'
                +'</div>'
            );
            
            $('form', code).each(function() {});
        };

        let parser = new DOMParser();
        let codeParser = parser.parseFromString(code, 'text/html');
        
        $(codeParser).find('style').remove();
        $(codeParser).find('script').remove();
        $(codeParser).find('noscript').remove();

        let codeParserText = codeParser.body.innerHTML.replace(/<.*?>/g," ").replace(/ +/g," ").replace(/\n\s*\n\s*\n/g, '\n\n');

        $('#sc-content-panel').append(
            '<div class="row mb-3">'
                +'<div class="col-12">'
                    +'<div class="card">'
                        +'<div class="card-body">'
                            +'<div class="accordion-wrapper accordion-parent">'
                                +'<div class="accordion-title">'
                                    +'<h3>Home Page Text'
                                        +'<div class="more-info-arrow closed">'
                                            +'<svg xmlns="; title="Click for more information" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#929dab" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-chevron-down hidden-link-arrow">'
                                                +'<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>'
                                                +'<path d="M6 9l6 6l6 -6"></path>'
                                            +'</svg>'
                                        +'</div>'
                                    +'</h3>'
                                +'</div>'
                                +'<div class="accordion-body">'
                                    +'<div class="accordion-wrapper acc-main"><pre class="pre-line">'+ codeParserText +'</pre></div>'
                                +'</div>'
                            +'</div>'
                        +'</div>'
                    +'</div>'
                +'</div>'
            +'</div>'
        );
    };

    let getCode = function(file) {

        $.get(file, formAcc);
    };

    getCode('/source-code.txt');
};

TIA

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744854145a4597305.html

相关推荐

  • jquery - How do I stop 3rd party cookies? - Stack Overflow

    I have written a script in jQuery which takes a web site's source code, goes through it and extrac

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信