Click here to Skip to main content
15,393,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've run into a weird problem with Chrome and Facebook Pixel and I'm wondering if others have run into the same thing.

In Chrome, and only in Chrome, javascript confirmation dialogs suddenly went haywire on our site recently. The issue is that the dialog will pop up just fine, but then be immediately dismissed without user input. It just pops up and then instantly goes away. This is a big problem, because if you can't click OK on the confirmation dialog then whatever you were trying to do won't happen.

To clarify, this has nothing to do with Chrome's fixes for javascript dialog abuse like dismissing the dialog if you change tabs. The behavior I'm talking about is obviously not working as intended, as the dialog should either show and allow interaction or not show at all.

What I have found is that this problem goes away if I comment out the code for Facebook Pixel from the masterpage. It seems as if whatever event tracking Pixel is doing is interfering with javascript dialogs, but only in Chrome. Other browsers are fine.

Sample code is below, if others who use Facebook Pixel can replicate this that would be good to know, I'm searching for a workaround but so far the best I've come up with is to replace the Pixel javascript code with their IMG option.

Facebook Pixel code:

<script>
    !function(f,b,e,v,n,t,s)
    {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
    n.callMethod.apply(n,arguments):n.queue.push(arguments)};
    if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
    n.queue=[];t=b.createElement(e);t.async=!0;
    t.src=v;s=b.getElementsByTagName(e)[0];
    s.parentNode.insertBefore(t,s)}(window,document,'script',
    'https://connect.facebook.net/en_US/fbevents.js');
    fbq('init', '<YOURID>');
    fbq('track', 'PageView');
</script>
<noscript>
    <img height="1" width="1"
    src="https://www.facebook.com/tr?id=<YOURID>&ev=PageView
    &noscript=1"/>
</noscript>


Button for launching dialog:

<asp:Button runat="server" ID="TestButton" OnClientClick="return confirm('Are you sure that you want to do this?');" Text="Confirm" />


What I have tried:

I found that removing Facebook Pixel javascript resolves the problem. Just commenting out the fbq('track', 'PageView') line does the trick. But of course, I need Facebook Pixel to keep working or I'll get a talking to.
Posted
Updated 21-Aug-19 11:09am
Comments
Patkós Csaba 26-Jul-19 1:02am
   
@StatementTerminator Did you find a solution to this problem? I am having the same issue, but didn't find any workaround yet.
StatementTerminator 26-Jul-19 9:52am
   
Nope, the only workaround I've found so far is to just ditch the javascript for Pixel and use their IMG solution instead.
Patkós Csaba 29-Jul-19 0:53am
   
Hey, thanks. I'll try that.

1 solution

Update: The problem magically went away with the latest release of Chrome, so it looks to be fixed.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900