summaryrefslogtreecommitdiffstats
path: root/ppapi/examples/scripting/post_message.html
blob: 883d3128d0af63175a995b0dce7978b7074f5c00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
  <!--
  Copyright (c) 2011 The Chromium Authors. All rights reserved.
  Use of this source code is governed by a BSD-style license that can be
  found in the LICENSE file.
  -->
<head>
  <title>postMessage Example</title>
</head>

<body>

<script type="text/javascript">

function SendString() {
  plugin = document.getElementById('plugin');

  // If we haven't already done it, set up an 'onmessage' function.  This will
  // get invoked whenever the plugin calls Instance::PostMessage in C++ (or
  // PPB_Messaging::PostMessage in C).  In this case, we're expecting a bool to
  // tell us whether the string we passed was a palindrome.
  if (!plugin.onmessage) {
    plugin.onmessage = function(message_event) {
      if (message_event.data) {
        alert("The string was a palindrome.");
      } else {
        alert("The string was not a palindrome.");
      }
    }
  }

  var inputBox = document.getElementById("inputBox");

  // Send the string to the plugin using postMessage.  This results in a call
  // to Instance::HandleMessage in C++ (or PPP_Messaging::HandleMessage in C).
  plugin.postMessage(inputBox.value);
}

</script>

<input type="text" id="inputBox" name="inputBox" value="ablewasiereisawelba"/>
<p>
<button onclick='SendString()'>Is Palindrome</button>
<object id="plugin" type="application/x-ppapi-post-message-example"
        width="0" height="0"/>
<hr>
</body>
</html>