1 <!DOCTYPE html> 2 <html> 3 <!-- 4 Copyright (c) 2011 The Chromium Authors. All rights reserved. 5 Use of this source code is governed by a BSD-style license that can be 6 found in the LICENSE file. 7 --> 8 <head> 9 <title>postMessage Example</title> 10 <script> 11 12 function HandleMessage(message_event) { 13 if (message_event.data) { 14 alert("The string was a palindrome."); 15 } else { 16 alert("The string was not a palindrome."); 17 } 18 } 19 20 function AddListener() { 21 var plugin = document.getElementById("plugin"); 22 plugin.addEventListener("message", HandleMessage, false); 23 } 24 document.addEventListener("DOMContentLoaded", AddListener, false); 25 26 </script> 27 </head> 28 29 <body> 30 <script> 31 32 function SendString() { 33 var plugin = document.getElementById("plugin"); 34 var inputBox = document.getElementById("inputBox"); 35 36 // Send the string to the plugin using postMessage. This results in a call 37 // to Instance::HandleMessage in C++ (or PPP_Messaging::HandleMessage in C). 38 plugin.postMessage(inputBox.value); 39 } 40 41 </script> 42 43 <input type="text" id="inputBox" name="inputBox" value="ablewasiereisawelba"/> 44 <p> 45 <button onclick="SendString()">Is Palindrome</button> 46 <object id="plugin" type="application/x-ppapi-post-message-example" 47 width="1" height="1"/> 48 <hr> 49 </body> 50 </html> 51 52