trigger function on separate window using intercom.js

1.9k Views Asked by At

When trying to use intercom.js I can print what my message is to the log in line 21 of the index file

intercom.on('notice', function (data) {
    console.log(data);
    $messages.append($('<p>').text(data.message));
    document.title = '(' + $messages[0].childNodes.length + ') ' + title;
});

Is there any way when clicking it simply to trigger an alert on the other page.

1

There are 1 best solutions below

1
On BEST ANSWER

In the read me file it gives you a basic code

// run this in multiple tabs!
var intercom = Intercom.getInstance();

intercom.on('notice', function(data) {
    console.log(data.message);
});

intercom.emit('notice', {message: 'Hello, all windows!'});

Put the emit code on the page with the button, put the on code on the page where you want the alert to appear [of course change the console line to an alert.]


So making the alert happen would be:

Page 1 [Page with the alert]:

var intercom = Intercom.getInstance();

intercom.on('notice', function(data) {
    alert(data.message);
});

Page 2 [Page with the button]:

function broadcast () {
    var intercom = Intercom.getInstance();   
    intercom.emit('notice', {message: 'Hello, all windows!'});
}
document.getElementById("myButtonId").addEventListener("click", broadcast , false);