Make the widget appear only if the url of the page contains the words CHARTER | DESTINATIONS

Hello,

Could you tell me how using the JS API, I can display the widget only if the URL contains the word CHARTER or destinations?

Many thanks in advance.

Hi Steven!

Are you confident you’d like to achieve that result using JS API specifically?
This could be very easily achieved with LiveChat without using any kind of API - if you’re interested, do let me know :slight_smile:

In terms of achieving this with JS API

  1. If you have the option to - easiest way to only display chat on specific pages would be to implement the LiveChat script only on those pages
  2. If you don’t have the possibility to add our JS to those pages only, you could use window.location.href (I’m attaching a documentation of that below):
    JavaScript Window Location
    to get the information about the url of page visitor is currently browsing and then implement a script along the lines of:
var location === window.location.href
if(location.includes('charter'  ||  'destinations')) >= 0){
 our chat script here
}

which simply translates to,
if URL visitor is on contains a string ‘charter’ or ‘destinations’ load the LiveChat script

Alternatively instead of loading or not loading our script entirely based on the url - you could load it everywhere and set default position of the widget to ‘Always hide minimized widget icon’ here

and then load our script everywhere by default but show it based on url like this:

var location === window.location.href
if(location.includes('charter'  ||  'destinations')) >= 0){
 LiveChatWidget.call("maximize");
}

I hope that helps! :slight_smile:

1 Like