php - Listening for 2 Pusher apps in same page using Javascript -


i have been using pusher quite few months success. won't go details of "push" part of solution because works already. issue listener side when try listen second app. please note said second app not second channel on same app.

here have has worked @ least 6 months , continues work until try add second version of on same html/php page in head section.

i have changed keys info obvious reasons.

how can add second copy of pointing second app within pusher?

my concern have issues if there things identical variables such channel. have tried renaming channel channel 2 , pusher pusher 2 quits working..

<!-- start pusher code -->   <script src="https://d3dy5gmtp8yhk7.cloudfront.net/2.1/pusher.min.js" type="text/javascript"></script>   <script type="text/javascript">      var pusher = new pusher('0000000000');     var channel = pusher.subscribe('appname');      channel.bind('channelname', function(data) {      myurl = 'http://www.google.com';      newwindow=window.open(myurl,data.cuid,'height=800,width=950,scrollbars=yes');      });   </script>   <!-- end pusher code --> 

you can use self-executing closure:

( function() {   // code } )(); 

to ensure variables don't clash. also, remember declare variables using var or leak global scope.

if possible, include pusher <script> tag once.

<script src="https://d3dy5gmtp8yhk7.cloudfront.net/2.1/pusher.min.js"></script> <!-- start pusher code --> <script> ( function() {   var pusher = new pusher('app_key_1');   var channel = pusher.subscribe('appname');    channel.bind('channelname', function(data) {      var myurl = 'http://www.google.com';      var newwindow=window.open(myurl,data.cuid,'height=800,width=950,scrollbars=yes');    }); } )(); </script> <!-- end pusher code -->  <!-- start pusher code --> <script> ( function() {   var pusher = new pusher('app_key_2');   var channel = pusher.subscribe('appname');    channel.bind('channelname', function(data) {      var myurl = 'http://www.google.com';      var newwindow = window.open(myurl,data.cuid,'height=800,width=950,scrollbars=yes');    }); } )(); </script> <!-- end pusher code --> 

i've used 2 different application keys confirm connecting 2 different applications.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -