Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple Example for Pubnub messagin
<!DOCTYPE html>
<!-- open up this same page in two instances of the brower that way you can see the message pop up in the other instances of the browser-->
<!-- make sure to add the jquery.js file to the same location as this file -->
<!-- Author: Fernando Zamora 9 October 2014 -->
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Home</title>
<script src="jquery.js" type="text/javascript"></script>
<!-- Include the PubNub Library -->
<script src="https://cdn.pubnub.com/pubnub.min.js" type="text/javascript"></script>
<!-- Instantiate PubNub -->
<script type="text/javascript">
var user = "larry";
var PUBNUB_demo = PUBNUB.init({
publish_key: 'demo',
subscribe_key: 'demo'
});
</script>
<script type="text/javascript">
PUBNUB_demo.subscribe({
channel: 'demo_tutorial',
message: function(m){alert(m.name + " says: " + m.text)}
});
</script>
</head>
<body>
<a class="confirmLink" href="#">Click here</a>
<!--this script place below the confirmLink so that binding will work -->
<script type="text/javascript">
$(".confirmLink").click(function(e) {
e.preventDefault();
confirmClick();
});
function confirmClick(){
// Publish a simple message to the demo_tutorial channel
PUBNUB_demo.publish({
channel: 'demo_tutorial',
message: {"text":"Hi!", "name":user}
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment