From 53238c47ce85b2746d8d3375dc909aff892de3e7 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 22 Apr 2014 19:01:59 +0200 Subject: [PATCH] null and type check what comes through postmessage --- js/reveal.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index 42edf90..1238f9f 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -575,11 +575,16 @@ var Reveal = (function(){ if( config.postMessage ) { window.addEventListener( 'message', function ( event ) { - var data = JSON.parse( event.data ); - var method = Reveal[data.method]; + var data = event.data; - if( typeof method === 'function' ) { - method.apply( Reveal, data.args ); + // Make sure we're dealing with JSON + if( data.charAt( 0 ) === '{' && data.charAt( data.length - 1 ) === '}' ) { + data = JSON.parse( data ); + + // Check if the requested method can be found + if( data.method && typeof Reveal[data.method] === 'function' ) { + Reveal[data.method].apply( Reveal, data.args ); + } } }, false ); }