1

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.

1252748
  • 14,597
  • 32
  • 109
  • 229

1 Answers1

2

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);
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • That works brilliantly. Thanks so much. Was totally above my head, but this makes sense. Thanks! – 1252748 Jul 12 '13 at 05:08