0

I am attempting to embed a chat widget if utm_source=VALUE (any of these values)

Here is the surrounding code:

var ref1 = document.referrer;
IF STATEMENT HERE
  {
    alert("Welcome to Ellas Bubbles");
    s1.src='https://embed.tawk.to/620675459bd1f31184dc28c0/1frkjk5mj';
  }

You can test it here: https://ellasbubbles.com

I have tried the following, which is only working on 'ccov':

if ((ref1.indexOf('ccov') || ref1.indexOf('top10') || ref1.indexOf('cenf') || ref1.indexOf('aip') || (getcookie('track-page-1').indexOf('ccov')>-1) || (getcookie('track-page-1').indexOf('top10')>-1) || (getcookie('track-page-1').indexOf('cenf')>-1) || (getcookie('track-page-1').indexOf('aip')>-1)) > -1)

I have also tried this:

  if ((ref1.indexOf('ccov' || 'top10' || 'cenf' || 'aip') || (getcookie('track-page-1').indexOf('ccov' || 'top10' || 'cenf' || 'aip')>-1)) > -1)
  {
    s1.src='https://embed.tawk.to/620675459bd1f31184dc28c0/1frkjk5mj';
  }

Which is also only working on the first value, 'ccov'.

I have also tried this:

if ((ref1.indexOf('ccov', 'top10', 'cenf', 'aip') || (getcookie('track-page-1').indexOf('ccov', 'top10', 'cenf', 'aip')>-1)) > -1)

Which is also only working on the first value

Is there a better way to go about this?

Tanner T
  • 25
  • 5
  • It embeds a widget by reading the query parameter. If it contains any of these values, the chat widget should be embedded. I just updated my original question with the surrounding code – Tanner T Feb 11 '22 at 17:36
  • `'ccov' || 'top10' || 'cenf' || 'aip'` _is_ `"ccov"`. [`indexOf`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) only accepts one argument as the value to search for. The second argument is the index to start searching for. Please _[edit]_ your post and explain what it’s supposed to do. – Sebastian Simon Feb 11 '22 at 17:37
  • `[ "ccov", "top10", "cenf", "aip" ].some((value) => ref1.includes(value))`. Familiarize yourself with [how to access and process nested objects, arrays or JSON](/q/11922383/4642212) and use the available static and instance methods of [`Array`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array#Static_methods). – Sebastian Simon Feb 11 '22 at 17:40
  • This question was closed, but I updated the above question and tried this: if ([ "ccov", "top10", "cenf", "aip" ].some((value) => ref1.includes(value)) || [ "ccov", "top10", "cenf", "aip" ].some((value) => getcookie('track-page-1').includes(value))) – Tanner T Feb 11 '22 at 17:43
  • and it is working, so thank you! Hopefully this will help someone else in the future who is stuck on .IndexOF – Tanner T Feb 11 '22 at 17:44

1 Answers1

0

I think your statements are incomplete. Before each || you need to condition to be satisfied. I’m writing on my phone so sorry this isn’t as specific but you need the >-1 before every ||. So instead of X || Y < z I think You need X < z || y < z.

Dharman
  • 30,962
  • 25
  • 85
  • 135
zoidberg
  • 41
  • 1
  • 7
  • I was actually able to resolve this with: if ([ "ccov", "top10", "cenf", "aip" ].some((value) => ref1.includes(value)) || [ "ccov", "top10", "cenf", "aip" ].some((value) => getcookie('track-page-1').includes(value))) { – Tanner T Feb 11 '22 at 18:12